Topic: less<complex> (Was: STL containers wit
Author: "Skip Sailors" <rsailors@wyoming.com>
Date: 1998/01/27 Raw View
1) Man, now I'm confused.
I thought that for all x being a numeric type that (x < x) is false, not
contradictory. Glad this is C++, not math.
2) (a + bi) < (a' + b'i ) iff (a < a') || (a == a' && (b < b')) would be ok
if you needed to store some complexes in a searchable container, but it is
arbitrary and kind of senseless to talk about a 2-dimensional point having a
1-dimensional ordering in the real world.
I pull this flavor of trick all the time when I need to keep orderless types
in a container that is designed to hold ordered types. I define an ordering
that may be non-sensical.
I hope that when I do this I recognize a weakness in the (meta)design that
requires such shenanigans. In a truly OO life the abstractions would model
the world.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Robert Stafford" <stafford@bindview.com>
Date: 1998/01/22 Raw View
Complex numbers can be ordered. There are several ways to order them --
therein lies the rub. There are alternative orderings of integers, too, but
only one "natural" order while the complex numbers have different orderings
that are equally useful (and "natural") in different contexts. It would be
problematic to single out one ordering as THE ORDERING of the complex
numbers as we single out the usual ordering of integers as THE ORDERING of
the integers.
Steve Clamage wrote in message <6a3g9s$lu6@engnews1.Eng.Sun.COM>...
>In mathematics, complex numbers cannot be ordered. Any ordering
>you impose msut result in internal contradictions, from what I
>remember of my analysis courses.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/01/23 Raw View
Robert Stafford wrote:
>
> Complex numbers can be ordered. There are several ways to order them --
> therein lies the rub. There are alternative orderings of integers, too, but
> only one "natural" order while the complex numbers have different orderings
> that are equally useful (and "natural") in different contexts. It would be
> problematic to single out one ordering as THE ORDERING of the complex
> numbers as we single out the usual ordering of integers as THE ORDERING of
> the integers.
>
There are no natural orderings of complex numbers. For any possible
ordering, for almost every complex number c, there exist pairs of
numbers a and b that are much closer to each other than either one is to
c, such that a>c and b<c. That is part of what makes any such ordering
"unnatural".
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Mike Davies <mike_davies@noco.demon.co.uk>
Date: 1998/01/23 Raw View
In article <6a529f$jdn$1@uuneo.neosoft.com>, Robert Stafford
<stafford@bindview.com> writes
>Complex numbers can be ordered. There are several ways to order them --
>therein lies the rub. There are alternative orderings of integers, too, but
>only one "natural" order while the complex numbers have different orderings
No. The complex numbers *cannot* be ordered. Any ordering of the complex
numbers leads to the relation x < x for some x, which leads to a
contradiction. Any reasonable computer implementation of the complex
numbers *can* be ordered however (simply interpret the pair of reals as
a bit pattern of fixed length and impose the natural binary number order
on this).
Mike
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Chris Uppal" <chris.uppal@ait.REMOVE-THIS.co.uk>
Date: 1998/01/23 Raw View
Mike Davies <mike_davies@noco.demon.co.uk> wrote in article
<NOmSXNAib8x0EwAJ@noco.demon.co.uk>...
> In article <6a529f$jdn$1@uuneo.neosoft.com>, Robert Stafford
> No. The complex numbers *cannot* be ordered. Any ordering of the complex
> numbers leads to the relation x < x for some x, which leads to a
> contradiction.
Way off subject for this newgroup, but I'm curious. Do you mean that this is a
provable result ?
If so, then what goes wrong with:
(a + bi) < (a' + b'i ) iff (a < a') || (a == a' && (b < b'))
-- chris
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/01/23 Raw View
Steve Clamage <clamage@Eng.Sun.COM> writes:
> In article 3725@pratique.fr, Valentin Bonnard <bonnardv@pratique.fr> writes:
> >I don't see how the notion of _type_ can be more or less
> >ordered than the notion of complex number. How can you say
> >that a type is greater than another one ?
>
> In mathematics, complex numbers cannot be ordered. Any ordering
> you impose msut result in internal contradictions, from what I
> remember of my analysis courses.
<OFF TOPIC>
In math, any set can be well ordered, including R and C but
also 'weird' sets (assuming the choice axiom). But the
ordering may not satisfy your notion of order (whatever it
is). In particullar, you may prove that no ordering satisfies
such an such 'nice' property.
</OFF TOPIC>
But there are also many ways to order typeinfo, and _all_
result in problems with beginners who assume that a.before(b)
iff b is derived from a.
But each implementation can choose a different ordering
for typeinfo, and I (and you) don't care about that,
because all what we want is _some order_. [Same reasonning
with complex<T>.]
The same goes for less<T*>, of course:
int a, b;
cout << (less<int*>()(&a, &b) ? "&b" : "&a") << " is greater.\n";
do it makes sens ? IMO, not more or less than
less<complex<T> >.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Theo Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>
Date: 1998/01/23 Raw View
Robert Stafford wrote:
> Complex numbers can be ordered. There are several ways to order them --
> therein lies the rub. There are alternative orderings of integers, too, but
> only one "natural" order while the complex numbers have different orderings
> that are equally useful (and "natural") in different contexts. It would be
> problematic to single out one ordering as THE ORDERING of the complex
> numbers as we single out the usual ordering of integers as THE ORDERING of
> the integers.
>
> Steve Clamage wrote in message <6a3g9s$lu6@engnews1.Eng.Sun.COM>...
> >In mathematics, complex numbers cannot be ordered. Any ordering
> >you impose msut result in internal contradictions, from what I
> >remember of my analysis courses.
To be even more accurate, natural ordering for integers, floats means that there
is an ordering
that is compatible with the standard + and * operations. There are orders for
complex numbers, but none can be defined to be compatible with these operations.
As pointed out, it would be therefore extremely misleading to define operator<
for those. Now, NOT HAVING sets for complex numbers is mathematically as silly as
having an operator< for those !!!
Now comes in the semantic of the less class... my understanding is that it could
be defined (I do not claim that it is the way it is defined, my knowledge does
not go that far) only as an ARBITRARY ordering used by the STL map and sets for
internal data structure reasons ONLY since it is the only place where it is used
in the standard (but I may be wrong...) and since stl sets and maps do not
require the comparison operator to be compatible with operations (that may even
not exist).
IF this claim is true then nothing requires less to have a reasonnable
mathematical meaning and maybe a specialisation of the less template for complex
numbers can be added. Actually , generalizing this for all types without having
to introduce many special casespoints out a problem for which I have no answer:
Assume that there are two template definitions for less: the usual one and
another one that I will
call fallbackLess (that would for example compare the adresses of the two
elements being passed
as argument).
Is there a technique that I could use to obtain the following behavior:
use the less template when possible(i.e. when operator< is defined for the
class) and the
fallback Less template otherwise ?
Now, I might be wrong with my assumptions about less.... so we will all have to
define our own version of a less like function for complex numbers and all the
other unordered types.... :-(
As a side note: when I started with stl, I was extremely annoyed at first with
the fact that sets required the type to have an order (I used it for sets of 2D
points which as complex numbers do not
have a standard ordering), as mathematical sets are not ordered ..... until I
realized why the order was used for !!! I'm sure I'm not alone. That's why I
believe that the meaning of less should not be too much correlated with the
mathematical meaning.
--
--------------------------------------------------------------------------------
Theodore Papadopoulo (papadop@sophia.inria.fr)
Projet Robotvis, INRIA - Sophia Antipolis,
2004, route des Lucioles, BP 93, 06902 Sophia Antipolis Cedex -- FRANCE
Phone: (33) 04 92 38 76 01, Fax: (33) 04 92 38 78 45
--------------------------------------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/01/23 Raw View
Mike Davies wrote:
>
> No. The complex numbers *cannot* be ordered. Any ordering of the complex
> numbers leads to the relation x < x for some x, which leads to a
> contradiction. Any reasonable computer implementation of the complex
> numbers *can* be ordered however (simply interpret the pair of reals as
> a bit pattern of fixed length and impose the natural binary number order
> on this).
Absolute non-sens.
Of course they can. Actually, if you admit the choice axiom,
every mathematicall set can _well_ ordered (ie every set as
a smallest element). Yes, including R and C ! Even without
this axiom, it's clear that you can have an order for C.
In CS (as opposed to math), this is even more obvious: you
can always define the ordering on bits, or something like
that.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: 1998/01/23 Raw View
"Chris Uppal" <chris.uppal@ait.REMOVE-THIS.co.uk> wrote:
: Mike Davies <mike_davies@noco.demon.co.uk> wrote in article
: <NOmSXNAib8x0EwAJ@noco.demon.co.uk>...
: > In article <6a529f$jdn$1@uuneo.neosoft.com>, Robert Stafford
: > No. The complex numbers *cannot* be ordered. Any ordering of the complex
: > numbers leads to the relation x < x for some x, which leads to a
: > contradiction.
: Way off subject for this newgroup, but I'm curious. Do you mean that this is a
: provable result ?
: If so, then what goes wrong with:
: (a + bi) < (a' + b'i ) iff (a < a') || (a == a' && (b < b'))
Thinking geometrically, < for the reals means to the left of. But i
is neither left nor right of 0 and is also not equal.
Thinking algebracially, if i < 0 then i*i = -1 > 0 because
multiplication by a negative reverses the inequality; if i > 0 then
i*i = -1 > 0 because multiplication by a positive preserves the
inequality. Clearly, i != 0. There are no other choices.
Complex numbers form an unordered field. You can place any order you
like on them as long as you have no desire to preserve the properties
of the _numbers_ in mathematics.
John
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1998/01/25 Raw View
Valentin Bonnard <bonnardv@pratique.fr> writes:
|> In CS (as opposed to math), this is even more obvious: you
|> can always define the ordering on bits, or something like
|> that.
Just a nit (since it really doesn't invalidate what Valentin is saying,
just his example): defining the ordering on bits typically doesn't work,
since 0.0 should compare equal to -0.0. On most hardware, however,
these two values have different bit representations.
Of course, the underlying implementation of complex< T > is the same as
pair< T , T >, and the standard does define an order on that. As for
the argument that ordering complex contradicts mathematics, I am totally
in agreement with regards to operator< (which I frequently find in my
math textbooks), but I don't see the relevance with regards to less<
complex< T > > (which I can't find mentioned in any of my math
textbooks).
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient e objet --
-- Beratung in objektorientierter Datenverarbeitung
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Pete Becker <petebecker@acm.org>
Date: 1998/01/26 Raw View
John Potter wrote:
>
>
> Complex numbers form an unordered field. You can place any order you
> like on them as long as you have no desire to preserve the properties
> of the _numbers_ in mathematics.
But that's exactly the point: the template set requires a predicate that
defines an ordering of its contents for purposes of the container's
internal implementation, not for purposes of mathematics. A perfectly
useful predicate can be defined like this:
template <class T> bool less( complex<T> t1, complex<T> t2 )
{
return (t1.re == t2.re) ? (t1.imag < t2.imag) : (t1.re < t2.r3);
}
Sure, it's mathematically useless. But we're not doing mathematics here,
we're implementing a container, and it works just fine.
-- Pete
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/01/21 Raw View
In article 3725@pratique.fr, Valentin Bonnard <bonnardv@pratique.fr> writes:
>Matt Austern <austern@isolde.mti.sgi.com> writes:
>
>> Valentin Bonnard <bonnardv@pratique.fr> writes:
>>
>> > On a related topic, I can't find a definition of:
>> > - less<complex>
>> > - less<typeinfo>
>> > in CD2. Is it an intentionnal ommission ? Shouldn't less<> be
>> > defined for every type with op== ?
>>
>> No. Defining less<typeinfo> might be reasonable, but defining
>> less<complex<T> > would be a terrible mistake. Complex numbers are
>> not ordered.
>
>I don't see how the notion of _type_ can be more or less
>ordered than the notion of complex number. How can you say
>that a type is greater than another one ?
In mathematics, complex numbers cannot be ordered. Any ordering
you impose msut result in internal contradictions, from what I
remember of my analysis courses.
Imposing an implementation-dependent ordering on typeinfo doesn't
have that kind of problem: it doesn't really matter whether
ostream compares "greater" or "less" than list<int>. In fact, class
typeinfo has a member function "before", which supplies an arbitrary
ordering. You can't make any portable assumptions about the meaning
of the ordering, but it does allow you to sort typeinfo data
for the purpose of searching lists, for example.
You could similarly impose an arbitrary ordering on complex values in
C++, but because "greater" and "less" have agreed-upon meaning for
numbers (unlike types), it would be a bad idea.
---
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]