Hacker News new | past | comments | ask | show | jobs | submit login
Calculating the norm of a complex number (thegreenplace.net)
64 points by mfrw 3 months ago | hide | past | favorite | 46 comments



>Since complex numbers are also a vector space (of dimension 1)

This statement seems very likely to confuse someone who doesn't know about or understand how to compute the norm of a complex number.

Complex numbers are a 1-dimensional vector space over the complex numbers themselves, but are probably more readily understood as a two-dimensional vector space over the reals. Any field is a vector space of dimension 1 over itself.


He does this to justify that we can define a norm over C, because the definitions speaks about vector spaces.

For me that section is not necessary, because he justifies the formula for the norm based on the definition of the norm, which in turn is historically justified by the norm over R2, which is by no doubt the first example of norm discovered (Pythagoras theorem).


>> He does this to justify that we can define a norm over C

Yeah, but computing z* really involves taking apart the complex number and fiddling with the real coefficient of the imaginary part. zz* looks like an operation in C, but it's kind of not.


For a real number `x`, does computing `-x` require "taking apart the real number and fiddling with the sign bit"? I think of negation as a real operation in R, namely a reflection about the origin, and conjugation a a real operation in C, namely a reflection about the real axis.


The trouble is that complex conjugation is not holomorphic (analytic) over the complex numbers.

It's incredibly useful as an operator, and it appears all over the place in Hilbert spaces and other complex-probability situations, but fundamentally it defies attempts to use it for analytic purposes (like differential equations or contour integration).

Useful when you need to treat the complex plane as a vector space or are interested in the topology of a complex function, but a pain to deal with in almost any other context.


For those of you wondering why on Earth such a simple function wouldn't be well-behaved, it can help to think about what you can do with the conjugate.

In particular, since sums of holomorphic functions are holomorphic, the sum f(z) = z + z* of the identity function g(z) = z and conjugate function h(z) = z* would need to be holomorphic. But z + z* cancels out the imaginary part of z and therefore maps the complex plane to the real line - and it should be obvious that a map from C to R cannot possibly preserve the properties of C in any intuitive way.

Roughly speaking, the conjugate fails to be holomorphic because it maps C to its mirror image, rather than C itself, in much the same way that reflecting a circle is different from rotating it.


Is there an analytic function that approximates the conjugate, and can this approximation be made better and better by making the function more complicated?

Edit: no, it can't be done because the Cauchy-Riemann equations make no sense here.


For any smooth function (like the conjugate) it makes sense to ask whether there exist holomorphic functions that approximate it arbitrarily well.

However: Suppose that for every n > 0 there exists a holomorphic function f_n such that |f_n(z) - z| < 1/n for all z. Then |f_n(z)| <= |f_n(z) - z| + |z*| = |z| + 1/n by the triangle inequality. A consequence of Liouville's theorem is that any entire holomorphic function with polynomial growth is a polynomial; here in particular we would need to have f_n(z) = a_n z + b_n for some complex numbers a_n and b_n. For real x we would have |(a_n - 1)x + b_n| < 1/n for all x, so a_n = 1. For imaginary iy we would have |(a_n + 1)iy + b_n| < 1/n for all y, so a_n = -1, which is a contradiction.

In fact, if a sequence of holomorphic functions converges uniformely on compact sets, the limit is itself holomorphic because of Cauchy's theorem.


Constant functions are holomorphic without preserving the properties of C

The issue is that the Cauchy Riemann equations don't hold. (You would need 1==-1)


Picard's theorem tells us constant functions are the only example of that, though (more or less because 0 == -0 [1] and that's only true for 0).

[1] I sincerely apologize to anyone who works with floats for this statement.


No need to apologize, 0 == -0 even if we are talking about floats.


> The trouble is that complex conjugation is not holomorphic (analytic) over the complex numbers.

Even more generally, a real-differentiable function is complex differentiable iff its (Wirtinger) derivative with respect to z* is 0.


Does the problem boil down to selecting the real part of a complex number? Correct me if I'm wrong, but the conjugate of z is merely 2*Re(z) - z. For example, the conjugate of a + bi is 2*a - (a + bi) = a - bi.


There is no problem. This is just a non holomorphic function of C to C. Differentiable functions are the exception not the norm (no pun intended).


Maybe worth noting that it is real-analytic.


I don't understand the starting point of this blog post. Why should one intuitively think that |z|^2 = zz? I've never seen anyone been confused by this. It's like writing an article about why 2*3 can't be 5 or something.


> Why should one intuitively think that |z|^2 = zz?

I guess because it's true for the reals. But yeah, I agree anyone who has got 10 minutes into an explanation of complex arithmetic should have got that far... I guess it's directed at people not acquainted with complex numbers much at all


Because it happens to work when Z has no imaginary component.


You can try it out in Python directly which natively support complex numbers (just use j instead of i):

   >>> import math
   >>> z=1+2j
   >>> z*complex.conjugate(z)
   (5+0j)
   >>> math.sqrt((z*complex.conjugate(z)).real)
   2.23606797749979
   >>> abs(z)
   2.23606797749979
As we can see abs(z) does the right thing. Try it with a negative imaginary part too and "nicer" values:

   >> z = 3-4j
   >>> math.sqrt((z*complex.conjugate(z)).real)
   5.0
   >>> abs(z)
   5.0


Same in Julia, but no need to "import math", its already built in :D

    joe@zap:~ $ julia
                   _
       _       _ _(_)_     |  Documentation: https://docs.julialang.org    
      (_)     | (_) (_)    |
       _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
      | | | | | | |/ _` |  |
      | | |_| | | | (_| |  |  Version 1.10.5 (2024-08-27)
     _/ |\__'_|_|_|\__'_|  |
    |__/                   |

    julia> z=1+2*im
    1 + 2im

    julia> z*conj(z)
    5 + 0im

    julia> sqrt(z*conj(z))
    2.23606797749979 + 0.0im

    julia> abs(z)
    2.23606797749979


it isn't necessary in Python, either. GP is only importing it for square roots, but exponentiation (via the ** operator) by .5 works fine with complex numbers in Python as well. It even handles complex exponents (although you'd have to look up the branch cut semantics etc. in the documentation):

    >>> (1+1j)**(1+1j)
    (0.2739572538301211+0.5837007587586147j)
Ironically, the `math` library doesn't handle that:

    >>> math.pow(1+1j, 1+1j)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: must be real number, not complex


Definitely. I was mainly trying to avoid using `**` as non-Python users might be more familiar with '^' instead.


Works in Julia:

  julia> (1+im)^(1+im)
  0.2739572538301211 + 0.5837007587586147im


This is what made me fall in love with python. It's over now, but it was nice while it lasted.


Look the post on Common Lisp (SBCL interpreter) and you will see python as a toy language, as it has to import math :D


watch this:

  $ sbcl
  This is SBCL 2.4.8, an implementation of ANSI Common Lisp.
  * (setf z #C(1 2))
  #C(1 2)
  * (* z (conjugate z))
  5
  * (sqrt (* z (conjugate z)))
  2.236068
  * (abs z)
  2.236068


Conjugate is also a method:

  x=1
  x.conjugate()

  x=1+2j
  x.conjugate()


Multiplying any two complex numbers 'a' and 'b' gives you a complex number z whose magnitude is the magnitude of 'a' times the magnitude of 'b' (that's covered in the article). I always thing of a 'complex conjugate' as a reflection across the real number line (i.e. has the opposite angle or 'phase'), so when a complex number and its conjugate are multiplied the angle disappears and you're left with no imaginary component, thus just the real part which IS the magnitude. (As a^2 + 0 = c^2)

I hadn't worked with complex numbers much for most of my life, but getting into quantum computing recently it is ALL complex numbers (and linear algebra). It's fascinating (for a certain mindset at least, which I guess I fall into), but it is a lot of mental work and repetition before it starts to feel in any way 'comfortable'.


> Why z squared is not a norm-square Now it's time to go back to the question we started the post with. Why isn't zz (or z^2) the norm-square? [several paragraphs later]. Looking at the formal definition of the norm, it's clear right away that won't do. The norm is defined as a real-valued function, whereas zz is not real-valued.

That much is clear much righter away just by noticing that for the simplest imaginary number imaginable (z=i) zz is negative but the norm-squared is positive-valued.


Not exactly a plane/normal reply:

IMHO, much simplier if use dual numbers[0] in lisp/lambda calculus context aka let a=lisp car and b-epsilon be lisp cdr.

Then normal calculations can also be symbolic, even if complex.

Although, per Lewis Caroll's concept of imaginary numbers with no concept of 'time', this doesn't quite work per functions/lists needing 'time to compute' a result.

Guess why Lewis Carrol's 'turing' white rabbit was always late. ?? car functions are real & cdr (functions) imaginary until realistically evaluated/looked @.

White rabbit never had time to get rid of at least one free variable of squareroot(i) = 0. Can't think outside the box if can't complete the square / define the square boundaries.

aka escape 0/'hole'. No going blue over 'escape, aboard, retry?' too!

Although, one would thing endless repetitive real quad (quadriatic/quadraceps) exercises would lead to declining/-1 quad issues[3] at some point in the narrative. That'd require defining a lot of axionomic booles though. (Wachowski 'The Matrix' contructs not withstanding).

If Lewis Carrol had known Andrey Markov[0], would the white rabbit have been able to learn the concept of time? (assumming Giuseppe Peano[1] doesn't enter the looking glass and the turing white rabbit stops reading the (sin() sub 0 * sin() sub 1 * .... sin() sub n) sequence / learns to complete the square at some point). -----

[0] : https://www.youtube.com/watch?v=ceaNqdHdqtg

[1] Giuseppe Peano. https://en.wikipedia.org/wiki/Peano_axioms

[2] Andrey Markov. https://en.wikipedia.org/wiki/Markov_chain

[3] https://en.wikipedia.org/wiki/Imaginary_unit


A simple demonstration of why this is necessary is to consider the distance between the points 1 and i on the complex plane. If you naively compute the distance between them using the familiar Euclidean formula √(a²+b²) you get:

√(1²+i²) = √(1-1) = 0

That can't be right...


Sorry, it was a poor reference to this:

https://www.reddit.com/r/mathmemes/s/c7gtvXrnz8


> If you naively compute the distance between them using the familiar Euclidean formula √(a²+b²)

That formula may be familiar, but it doesn’t compute a distance.

A simple demonstration of why this is necessary is to consider the distance between the points 3 and 4. If you naively compute the distance between them using the familiar Euclidean formula √(a²+b²) you get:

√(3²+4²) = √(9+16) = √(25) = 5

That can't be right...


Even simpler is trying to calculate |i| (i.e. the distance between the points 0 and i on the complex plane) as √i² = √-1 = i.


you are calculating inner product of otrhogonal vectors. For distance it should be abs(a-b) it will result to sqrt(2).


The article has too narrow of definition of what a norm is--since around 1910 or so, we've had to have a more expansive notion of what can be a norm.

e.g. the norm for Minkowski's space-time can be negative and does not satisfy the triangle inequality.

Imagine the sheer courage it took for Minkowski to propose a distance function which did not satisfy the triangle inequality.....the moral of the story is yes, learn up on these concepts, but don't be so wedded to somebody else's definition that you can't see when it should be relaxed and generalized.


Definitions are generalized all the time in mathematics. If Minkowski discovered something that was similar to a norm but not quite, that may be interesting, but it's still not a norm.

It also has nothing to do with the complex numbers where the canonical norm is, in fact, a norm.


The Minkowski Norm is, in fact, a norm: https://en.wikipedia.org/wiki/Minkowski_norm

// It also has nothing to do with the complex numbers //

The author of the linked article said that what he was describing was a norm because it satisfied the triangle inequality (among other things). I'm just pointing out that the (among other things) was enough for it to be a norm.

I certainly wished somebody had pointed out to me that not all norms need to satisfy the triangle property. There have been spaces where I wasted months of effort trying to find a norm which satisfied the triangle inequality, when a more minkowski-like norm would have been perfectly adequate.


You're playing semantic games. If it doesn't satisfy the triangle inequality it's a quasi-nonorm. When you say "norm", people understand it to imply the triangle inequality. That doesn't mean that spaces without a proper norm are useless.

Also your link links to a disambiguation page.


chuckle yes, because there are many areas which have norms which don't satisfy the triangle inequality.

I know, it came as a big surprise to me too.


you should read a textbook


Once you have decided to use the geometrical representation of the complex numbers, the justification of the norm of a complex number is Pythagoras's theorem.

If you want a more "complex numbers" justification, you can say that you want to make the vector "real" by moving it to the real line, so you multiply it by the inverse rotation of the complex number that you are looking at. If you instead multiply it by the conjugate, then you need to compute the square root of the output since it multiplies by the radius again.

I hope this helps!


I wondered what happens when you try to do this in more than 2 dimensions? It turns out that you can just extend the negation of the imaginary part before proceeding.

https://math.libretexts.org/Bookshelves/Abstract_and_Geometr....


Another way to think about it is that for a given z, we can write it as (r, θ) where r is |z| and θ is the rotation of that norm in complex space. The complex conjugate is (r, −θ). A product of complex numbers zw is (r, θ)×(s, τ)=(rs, θ + τ) so zz̄ = (r², θθ) = r² = |z|².


zz^* is fine for scalar complex numbers, but z^*z is nice because it also works for vectors. You can think of the complex conjugate as a special case of an adjoint, and the hermetian transpose is another special case.


zz* !? Why not z*z if you're nitpicking already? inb4 WFH killed Commutators.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: