[sage-devel] norm of a complex number

387 views
Skip to first unread message

Jason Grout

unread,
Apr 26, 2010, 3:21:45 PM4/26/10
to sage-...@googlegroups.com
Why does Sage say the norm of a complex number a+b*I is a^2+b^2?


sage: norm(1+2*I)
5


In MMA:

In[1]:= Norm[1+2*I]

Out[1]= Sqrt[5]

Wikipedia and mathworld both agree that the norm should be sqrt(5)
(i.e., the square root of the number times its conjugate).

Note that abs() seems right:

sage: abs(1+2*I)
sqrt(5)

Thanks,

Jason

--
To post to this group, send an email to sage-...@googlegroups.com
To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

John Cremona

unread,
Apr 26, 2010, 3:26:18 PM4/26/10
to sage-...@googlegroups.com
In number theory it is very useful to have this norm-alisation, as
well as the square root one also called abs. It's a special case of
the algebraic concept of norm(a) = product of conjugates of a.

If this was really a problem to non-number-theorists, we could
possibly live with it (possibly by defining a new function for this).

Other opinions may differ...

John

Gonzalo Tornaria

unread,
Apr 26, 2010, 3:48:16 PM4/26/10
to sage-...@googlegroups.com
On Mon, Apr 26, 2010 at 4:26 PM, John Cremona <john.c...@gmail.com> wrote:
> In number theory it is very useful to have this norm-alisation, as
> well as the square root one also called abs.  It's a special case of
> the algebraic concept of norm(a) = product of conjugates of a.

And the determinant of the action of a on C (as an R-vector space of
dimension 2) by complex multiplication.

However, this doesn't seem correct:

sage: sqrt(-3).norm()
-3

(I think the problem is with conjugates)

---

Anyhow, the norm for complex numbers is fine as is, but for the
symbolic ring, it makes me uneasy, e.g.

sage: SR(2).norm()
4
sage: CC(2).norm()
4.00000000000000
sage: QQ(2).norm()
2
sage: ZZ(2).norm()
...
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'norm'
sage: RR(2).norm()
...
AttributeError: 'sage.rings.real_mpfr.RealNumber' object has no attribute 'norm'


Gonzalo

John Cremona

unread,
Apr 26, 2010, 4:09:34 PM4/26/10
to sage-...@googlegroups.com
This is certainly a bug:

sage: a = sqrt(-3)
sage: a
sqrt(-3)
sage: a.conjugate()
sqrt(-3)

sage: bool(a==a.conjugate())
True

But I have no idea where to look for it, since symbolic expressions
are a mystery to me!

John

Rishikesh

unread,
Apr 26, 2010, 4:35:41 PM4/26/10
to sage-devel
There is abs() function which behaves likes Norm of Mathematica. I
think that the function names of sage are more appropriate.

Rishi

On Apr 26, 3:26 pm, John Cremona <john.crem...@gmail.com> wrote:
> In number theory it is very useful to have this norm-alisation, as
> well as the square root one also called abs.  It's a special case of
> the algebraic concept of norm(a) = product of conjugates of a.
>
> If this was really a problem to non-number-theorists, we could
> possibly  live with it (possibly by defining a new function for this).
>
> Other opinions may differ...
>
> John
>
> On 26 April 2010 20:21, Jason Grout <jason-s...@creativetrax.com> wrote:
>
>
>
>
>
> > Why does Sage say the norm of a complex number a+b*I is a^2+b^2?
>
> > sage: norm(1+2*I)
> > 5
>
> > In MMA:
>
> > In[1]:= Norm[1+2*I]
>
> > Out[1]= Sqrt[5]
>
> > Wikipedia and mathworld both agree that the norm should be sqrt(5) (i.e.,
> > the square root of the number times its conjugate).
>
> > Note that abs() seems right:
>
> > sage: abs(1+2*I)
> > sqrt(5)
>
> > Thanks,
>
> > Jason
>
> > --
> > To post to this group, send an email to sage-...@googlegroups.com
> > To unsubscribe from this group, send an email to
> > sage-devel+...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/sage-devel
> > URL:http://www.sagemath.org
>
> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/sage-devel

Jason Grout

unread,
Apr 26, 2010, 7:05:45 PM4/26/10
to sage-...@googlegroups.com
On 04/26/2010 02:48 PM, Gonzalo Tornaria wrote:
> On Mon, Apr 26, 2010 at 4:26 PM, John Cremona<john.c...@gmail.com> wrote:
>> In number theory it is very useful to have this norm-alisation, as
>> well as the square root one also called abs. It's a special case of
>> the algebraic concept of norm(a) = product of conjugates of a.
>
> And the determinant of the action of a on C (as an R-vector space of
> dimension 2) by complex multiplication.


I figured there were good mathematical reasons---I just wanted to know
how to address the issue if it came up in conversation or teaching.

I'll leave the inconsistencies/bugs noted elsewhere in this thread to
someone else to file a trac ticket or track them down.

Thanks,

Jason

kcrisman

unread,
Apr 26, 2010, 9:02:40 PM4/26/10
to sage-devel
I'm used to the number-theoretic norm too, so I wasn't so worried
about it. I would point out that having "native" support of Gaussian
integers/primes would be very convenient for educational purposes (for
instance, a.is_prime() is not implemented for SR, but unfortunately
also not for these guys... and I know it's not clear inside of which
ring a should be prime, so don't even complain about that).

On Apr 26, 4:09 pm, John Cremona <john.crem...@gmail.com> wrote:
> This is certainly a bug:
>
> sage: a = sqrt(-3)
> sage: a
> sqrt(-3)
> sage: a.conjugate()
> sqrt(-3)
>
> sage: bool(a==a.conjugate())
> True
>

Yeah, this is bad, and according to a.conjugate?? it seems to be
something wrong with our Ginac/Pynac use. Maybe a.conjugate() on SR
needs to only be automatically evaluated on things that can coerce to
RR or ZZ? It is possible that http://trac.sagemath.org/sage_trac/ticket/6244
is directly related, but I'm too lazy to see which Pynac changeset
this is related to.

Related (though not directly) tickets are http://trac.sagemath.org/sage_trac/ticket/7957,
http://trac.sagemath.org/sage_trac/ticket/7916, and
http://trac.sagemath.org/sage_trac/ticket/6862.

I've made this http://trac.sagemath.org/sage_trac/ticket/8775 and
marked it critical. Would be good to fix for 4.4.1.

- kcrisman

- kcrisman

Burcin Erocal

unread,
Apr 26, 2010, 9:16:00 PM4/26/10
to sage-...@googlegroups.com, ginac...@ginac.de
On Mon, 26 Apr 2010 18:02:40 -0700 (PDT)
kcrisman <kcri...@gmail.com> wrote:

> On Apr 26, 4:09 pm, John Cremona <john.crem...@gmail.com> wrote:
> > This is certainly a bug:
> >
> > sage: a = sqrt(-3)
> > sage: a
> > sqrt(-3)
> > sage: a.conjugate()
> > sqrt(-3)
> >
> > sage: bool(a==a.conjugate())
> > True
> >
>
> Yeah, this is bad, and according to a.conjugate?? it seems to be
> something wrong with our Ginac/Pynac use.

This is a bug in GiNaC:

ginsh - GiNaC Interactive Shell (ginac V1.5.7)
__, _______ Copyright (C) 1999-2010 Johannes Gutenberg University Mainz,
(__) * | Germany. This is free software with ABSOLUTELY NO WARRANTY.
._) i N a C | You are welcome to redistribute it under certain conditions.
<-------------' For details type `warranty;'.

Type ?? for a list of help topics.
> sqrt(-3);
sqrt(-3)
> conjugate(sqrt(-3));
sqrt(-3)


For conjugation, power objects just compute the conjugate of the basis
and the exponent, and construct a new power object from these. Here is
the relevant function:

http://pynac.sagemath.org/hg/file/3ece9ba22005/ginac/power.cpp#l805


Cheers,
Burcin

Johan Grönqvist

unread,
Apr 27, 2010, 4:06:18 AM4/27/10
to sage-...@googlegroups.com
2010-04-26 21:26, John Cremona skrev:

> In number theory it is very useful to have this norm-alisation, as
> well as the square root one also called abs. It's a special case of
> the algebraic concept of norm(a) = product of conjugates of a.
>
> If this was really a problem to non-number-theorists, we could
> possibly live with it (possibly by defining a new function for this).
>
> Other opinions may differ...
>


[Note: I come from physics, and do not use sage very much, but I would
like to replace my usage of mathematica/maple with sage.]


Short version:

I am surprised by

sage: norm(1+I)
2
sage: norm(vector([1+I]))
sqrt(2)

and I think sage should choose to change the definition of norm used on
complex numbers, as it wants to grow a broader user base.

The definition of norm on vectors is consistent with definitions of norm
according to wikipedia [0] and the springer encyclopedia of mathematics
[1], and (I believe) any book I have ever used. Those did not even
mention that there is an alternative definition of norm used in number
theory.

The norm on complex numbers is not consistent with viewing the complex
numbers as a two-dimensional real vector space, according to the
definitions mentioned above.





Long version:

I am very surprised by the current terminology. I think that many users
coming from physics and engineering would be surprised, and the mission
statement of sage, "Creating a viable free open source alternative to
Magma, Maple, Mathematica and Matlab", certainly seems to aim at a much
broader user community than number-theorists.

I would be very surprised if any of mathematica, maple and matlab used
the same convention as sage does, and given the mission statement, I
think that common terminology is a good thing.

The concept of a norm, as I have always encountered it, is well defined,
as in e.g. wikipedia[0] and other mathematics encyclopedias [1], [2], as
well as (I belive) any book I have used. This refers to vector spaces,
and I expect that most people use norms on vector spaces.

One property a norm is required to have is that for any vector v and
scalar a:

norm(a*v) == abs(a) * norm(v)

this holds for vectors

sage: norm( (1+I) * vector([1+I]) )
2
sage: abs(1+I) * norm( vector([1+I]) )
2

but not for complex numbers seen as 2-dimensional real vectors:

sage: norm( 2 * (1+I) )
8
sage: abs(2) * norm(1+I)
4


Regardless of that part, I think many people would, like me, be
surprised by the following results:

sage: norm(1+I)
2
sage: norm(vector([1+I]))
sqrt(2)

I find it very strange that the one element vector does not have the
same norm as the element it contains.

My suggestion is to change the definition of norm on complex numbers.

If that is not changed, I think that the docstring should clearly state
that sage deviates from the definitions of norm used by wikipedia,
springer, mathematica, maple and matlab, as I expect most people from
physics and engineering expect sage to follow the same definition as those.


Regards

Johan



[0]: <http://en.wikipedia.org/wiki/Norm_%28mathematics%29#Definition>
[1]: <http://eom.springer.de/N/n067340.htm>
[2]:
<http://www.mathacademy.com/pr/prime/browse.asp?LT=F&PRE=norm&LEV=B&TBM=Y&TAL=Y&TAN=Y&TBI=Y&TCA=Y&TCS=Y&TDI=Y&TEC=Y&TGE=Y&TGR=Y&THI=Y&TFO=Y&TNT=Y&TPH=Y&TST=Y&TTO=Y&TTR=Y>
Message has been deleted

Johan Grönqvist

unread,
Apr 27, 2010, 5:48:19 AM4/27/10
to sage-...@googlegroups.com
2010-04-27 11:37, Minh Nguyen skrev:
> Hi Johan,
>
> 2010/4/27 Johan Grönqvist<johan.g...@gmail.com>:
>
> The current documentation of norm() on complex numbers can be accessed
> from the Sage website [1]. That documentation leaves much to be
> desired, even though it makes the distinction between the complex norm
> and the absolute value of a complex number.

That documentation is much better than what I looked at. That certainly
satisfies my request for documentation.

> Would you upload a patch
> to the trac server to improve that documentation? If so, please CC me
> on the relevant ticket and I'd be more than happy to review your
> patch.
>

I would like to improve the following case.

----------------------
sage: norm?
Type: function
Base Class: <type 'function'>
String Form: <function norm at 0x1787938>
Namespace: Interactive
File:
/home/johan/Debian/sage-4.4.rc0/local/lib/python2.6/site-packages/sage/misc/functional.py
Definition: norm(x)
Docstring:
Returns the norm of x.

EXAMPLES:

sage: z = 1+2*I
sage: norm(z)
5
sage: norm(CDF(z))
5.0
sage: norm(CC(z))
5.00000000000000
-------------------

In particular I would like it to remark that the norm of the one element
vector is not the same as the norm of the element (for a complex number).

I hope to look at it later this week.

Thanks for your reply


Regards

Johan





> [1] http://www.sagemath.org/doc/reference/sage/rings/complex_number.html#sage.rings.complex_number.ComplexNumber.norm

YannLC

unread,
Apr 27, 2010, 7:18:46 AM4/27/10
to sage-devel


On Apr 27, 10:06 am, Johan Grönqvist <johan.gronqv...@gmail.com>
wrote:
>
> The concept of a norm, as I have always encountered it, is well defined,
> as in e.g. wikipedia[0] and other mathematics encyclopedias [1], [2], as
> well as (I belive) any book I have used. This refers to vector spaces,
> and I expect that most people use norms on vector spaces.

Just to add a link for people interested, the norm used now for
complex numbers comes from "field theory" [0]

[0] http://en.wikipedia.org/wiki/Field_norm

Gonzalo Tornaria

unread,
Apr 27, 2010, 7:29:24 AM4/27/10
to sage-...@googlegroups.com
2010/4/27 Johan Grönqvist <johan.g...@gmail.com>:
> The definition of norm on vectors is consistent with definitions of norm
> according to wikipedia [0] and the springer encyclopedia of mathematics [1],
> and (I believe) any book I have ever used. Those did not even mention that
> there is an alternative definition of norm used in number theory.

Here it is: http://en.wikipedia.org/wiki/Field_norm

> The norm on complex numbers is not consistent with viewing the complex
> numbers as a two-dimensional real vector space, according to the definitions
> mentioned above.

One caveat: "the" norm of a two-dimensional real vector space is not
canonical. In contrast, the norm of a two-dimensional field extension
is uniquely defined.

In the case of Sage, the norm of complex numbers is defined as the
norm for the field extension C over R.

Gonzalo

Johan Grönqvist

unread,
Apr 27, 2010, 8:25:35 AM4/27/10
to sage-...@googlegroups.com
2010-04-27 13:29, Gonzalo Tornaria skrev:
> 2010/4/27 Johan Grönqvist<johan.g...@gmail.com>:
>> Those did not even mention that
>> there is an alternative definition of norm used in number theory.
>
> Here it is: http://en.wikipedia.org/wiki/Field_norm
>

Thanks. Now I learned something new.

>> The norm on complex numbers is not consistent with viewing the complex
>> numbers as a two-dimensional real vector space, according to the definitions
>> mentioned above.
>
> One caveat: "the" norm of a two-dimensional real vector space is not
> canonical. In contrast, the norm of a two-dimensional field extension
> is uniquely defined.
>

True, but the argument was not about the particular choice of norm, but
the property

norm(a*v) == abs(a) * norm(v) [for any scalar a and any vector v]

required for any vector-space norm. That property does not seem to hold
for the field norm.

Regards

Johan

Dima Pasechnik

unread,
Apr 27, 2010, 9:45:46 AM4/27/10
to sage-devel
To summarize:

What is norm for number theorists, is pathology to the ordinary folks!
:-)


On Apr 27, 8:25 pm, Johan Grönqvist <johan.gronqv...@gmail.com> wrote:
> 2010-04-27 13:29, Gonzalo Tornaria skrev:
>
> > 2010/4/27 Johan Grönqvist<johan.gronqv...@gmail.com>:
> >> Those did not even mention that
> >> there is an alternative definition of norm used in number theory.
>
> > Here it is:http://en.wikipedia.org/wiki/Field_norm
>
> Thanks. Now I learned something new.
>
> >> The norm on complex numbers is not consistent with viewing the complex
> >> numbers as a two-dimensional real vector space, according to the definitions
> >> mentioned above.
>
> > One caveat: "the" norm of a two-dimensional real vector space is not
> > canonical. In contrast, the norm of a two-dimensional field extension
> > is uniquely defined.
>
> True, but the argument was not about the particular choice of norm, but
> the property
>
> norm(a*v) == abs(a) * norm(v)  [for any scalar a and any vector v]
>
> required for any vector-space norm. That property does not seem to hold
> for the field norm.
>
> Regards
>
> Johan
>
> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/sage-devel
> URL:http://www.sagemath.org

kcrisman

unread,
Apr 27, 2010, 9:46:29 AM4/27/10
to sage-devel
Great, thanks for this. I am changing the ticket to "not yet reported
upstream". Can you report it? Of course, if you have a quick fix,
that would be great too :) but I assume it would take a little more
thought to transform it from something that might work for a multi-
valued function to something that works for our "default" choice of
sqrt(-3) as \sqrt{3}*I.

- kcrisman

Burcin Erocal

unread,
Apr 27, 2010, 10:35:51 AM4/27/10
to sage-...@googlegroups.com
I sent the previous message to the GiNaC list as well, so it is already
reported upstream.

I don't have time to come up with a clean solution now. A quick
solution (apart from one that just leaves this unevaluated) is very
likely to lead to wrong results on examples I haven't though of, so I'm
reluctant to do that either.

If you can suggest a clean solution, using primitives like is_real(),
is_positive(), is_negative(), etc., then I can quickly implement that in
pynac though.

Thank you.

Burcin

Johan Grönqvist

unread,
Apr 29, 2010, 4:06:45 PM4/29/10
to sage-...@googlegroups.com
2010-04-27 11:37, Minh Nguyen skrev:
> Would you upload a patch
> to the trac server to improve that documentation? If so, please CC me
> on the relevant ticket and I'd be more than happy to review your
> patch.

I have opened ticket 8825 and attached a patch. It is a very small
change, and by no means complete. It merely adds two more examples to
the docstring and is intended to display the inconsistency in usage of
the term norm in sage.

I tried following the guides, but it is my first attempt at using both
mercurial and trac, so I may well have missed something. The patch is
against sage-4.4.rc0.

Regards

Johan
Reply all
Reply to author
Forward
Message has been deleted
0 new messages