Topic: Why 'template<class T> T norm(const complex<T>& v)' behaves so?


Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/10/28
Raw View
Nathan Myers <ncm@cantrip.org> writes:

> There's not much uniformity
> in how "norm" is defined in mathematics, so it was hard for the people
> who thought it should change to argue forcefully for a change.

Hum, to me a norm is a function n: E -> R+, where E is a vector
space, with the following properties:
- n(r*v) = |r|*n(v)  (r is a real)
- n(a + b) <= n(a) + n(b)

[Note: it implies
- n(0) = 0
- n(-v) = v]

Is there any disagrement on that ? Do you have another
definition ?

In particular, norm (std::complex<T>) is _not_ a norm.

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/


[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Piet Van Vlierberghe" <pieter.vanvlierberghe@lms.be>
Date: 1998/10/26
Raw View

>There's not much uniformity
>in how "norm" is defined in mathematics, so it was hard for the people
>who thought it should change to argue forcefully for a change.

What I remember from high school math:
"Norm" is defined very formally in vector mathematics. Moreover, complex
numbers are isomorphous to   2-dimensional vectors, which is where the norm
notation for complex numbers stems from in the first place.

Although the definition allows room for several distinct norms, even in
2-dimensional vector spaces, the squared euclidian distance to zero is NOT a
norm, since it fails to meet the triangle inequality. The euclidian distance
to zero DOES meet this requirement. So, as far as I can see, there is little
or no room for discussion.



[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/10/26
Raw View
Piet Van Vlierberghe<pieter.vanvlierberghe@@.lms.be.notrash> wrote:
>>There's not much uniformity
>>in how "norm" is defined in mathematics, so it was hard for the people
>>who thought it should change to argue forcefully for a change.
>
>"Norm" is defined very formally in vector mathematics.
>Although the definition allows room for several distinct norms, even in
>2-dimensional vector spaces, the squared euclidian distance to zero is NOT a
>norm, since it fails to meet the triangle inequality. The euclidian distance
>to zero DOES meet this requirement. So, as far as I can see, there is little
>or no room for discussion.

By that standard, there is no room for discussion at all.
The standard has been published, and the C++ norm is (AFAIK)
the same as the Fortran norm -- end of story.

If you were to define your own complex<> library (which I encourage)
you would probably better call the equivalent function "norm2".

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/



[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Theodore.Papadopoulo" <Theodore.Papadopoulo@sophia.inria.fr>
Date: 1998/10/27
Raw View
--------------D996B9FC20D6F3404FFD3C7F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Nathan Myers wrote:

>
> The real reason is that there were no numerics experts participating
> on the committee at the time this same question was raised there.
> Fortran (it was said) has something like it, and nobody felt confident
> to recommend changing it to be different.  There's not much uniformity
> in how "norm" is defined in mathematics, so it was hard for the people
> who thought it should change to argue forcefully for a change.
>
> Probably it should have been changed to "norm2".
>

Well that could have been a choice but many people might confuse this with the
L2-norm ...
squared_norm or norm_squared is certainly less ambiguous.

    Theo.

--
--------------------------------------------------------------------------------
        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
--------------------------------------------------------------------------------



--------------D996B9FC20D6F3404FFD3C7F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
Nathan Myers wrote:
<BLOCKQUOTE TYPE=CITE>&nbsp;
<BR>The real reason is that there were no numerics experts participating
<BR>on the committee at the time this same question was raised there.
<BR>Fortran (it was said) has something like it, and nobody felt confident
<BR>to recommend changing it to be different.&nbsp; There's not much uniformity
<BR>in how "norm" is defined in mathematics, so it was hard for the people
<BR>who thought it should change to argue forcefully for a change.
<P>Probably it should have been changed to "norm2".
<BR>&nbsp;</BLOCKQUOTE>
Well that could have been a choice but many people might confuse this with
the L2-norm ...
<BR>squared_norm or norm_squared is certainly less ambiguous.
<P>&nbsp;&nbsp;&nbsp; Theo.
<PRE>--&nbsp;
--------------------------------------------------------------------------------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Theodore Papadopoulo (papadop@sophia.inria.fr)

&nbsp;&nbsp; Projet Robotvis, INRIA - Sophia Antipolis,
&nbsp;&nbsp; 2004, route des Lucioles, BP 93, 06902 Sophia Antipolis Cedex -- FRANCE
&nbsp;&nbsp; Phone: (33) 04 92 38 76 01, Fax: (33) 04 92 38 78 45
--------------------------------------------------------------------------------</PRE>
&nbsp;</HTML>

--------------D996B9FC20D6F3404FFD3C7F--
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/10/22
Raw View
  template<class T> T norm(const complex<T>& v) returns v.real()*v.real() +
v.imag()*v.imag() - not a sqrt of this. But in math the norm of complex
numbers is usually a sqrt of this expression (ie the same that abs()
returns). Why it's so?




[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Gabriel Dos Reis <dosreis@DPTMaths.ens-cachan.fr>
Date: 1998/10/23
Raw View
>>>>> =ABVlad=BB, Vlad Harchev <vladhar@imimail.ssau.ru> wrote:

>   template<class T> T norm(const complex<T>& v) returns v.real()*v.real=
() +
> v.imag()*v.imag() - not a sqrt of this. But in math the norm of complex
> numbers is usually a sqrt of this expression (ie the same that abs()
> returns). Why it's so?

That is a known issue I would name a "bug" in the complex<>
specification. And it is infortunate. There'll be suggestions for
corrections (s/norm/squared_norm/).

--=20
Gabriel Dos Reis                   |  Centre de Math=E9matiques et de=20
dosreis@cmla.ens-cachan.fr         |         Leurs Applications
Fax : (33) 01 47 40 21 69          |   ENS de Cachan -- CNRS (URA 1611)
               61, Avenue du Pdt Wilson, 94235 Cachan - Cedex
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/10/23
Raw View
Vlad Harchev<vladhar@imimail.ssau.ru> wrote:
>
>  template<class T> T norm(const complex<T>& v) returns v.real()*v.real() +
>v.imag()*v.imag() - not a sqrt of this. But in math the norm of complex
>numbers is usually a sqrt of this expression (ie the same that abs()
>returns). Why it's so?

The real reason is that there were no numerics experts participating
on the committee at the time this same question was raised there.
Fortran (it was said) has something like it, and nobody felt confident
to recommend changing it to be different.  There's not much uniformity
in how "norm" is defined in mathematics, so it was hard for the people
who thought it should change to argue forcefully for a change.

Probably it should have been changed to "norm2".

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: elron@alum.mit.edu (Elron A. Yellin)
Date: 1998/10/23
Raw View
In article <70o1il$532$1@shell7.ba.best.com>, ncm@nospam.cantrip.org
(Nathan Myers) wrote:

>There's not much uniformity
> in how "norm" is defined in mathematics

This is exactly why the name 'norm' never should have been used (for anything).

Elron A. Yellin


[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: sbnaran@localhost.localdomain.COM (Siemel Naran)
Date: 1998/10/23
Raw View
On 23 Oct 98 14:15:08 GMT, Gabriel Dos Reis

>That is a known issue I would name a "bug" in the complex<>
>specification. And it is infortunate. There'll be suggestions for
>corrections (s/norm/squared_norm/).

Good.  Personally, I prefer "norm_squared", as this is the term some of
us (maybe all of us?) use.


--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------


[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 1998/10/23
Raw View
Vlad Harchev wrote:
>
>   template<class T> T norm(const complex<T>& v) returns v.real()*v.real() +
> v.imag()*v.imag() - not a sqrt of this. But in math the norm of complex
> numbers is usually a sqrt of this expression (ie the same that abs()
> returns). Why it's so?

The name is a bad one, and is one of the more bizarre mistakes I've seen
in the standard. However, it makes a lot of sense to have a function
that calculates the square of the norm, rather than (or in addition to)
a function that calculates the norm. It's quicker to calculate the
square of the norm, because you don't need a sqrt() call.
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]