Comparing two Complex Numbers

Hello!

How does Julia compare two complex numbers? Why it isn’t just looking the points and knowing, that if x1 < x2, y1 < y2, with the number being not smaller if x1 > x2 or y1 > y2.

What is the primary reason, why Julia is using Complex Numbers?

From manual: “Julia includes predefined types for both complex and rational numbers, and supports all the standard on them. are defined so that operations on any combination of predefined numeric types, whether primitive or composite, behave as expected.”

I am primarily using complex numbers for representing x and y axis of graphics plot, thus for me there is no reason to doubt that 0im < 1im. I can really doubt if square root of minus one > 0, but I can do some math with it.

Let’s say 200 + 300 * im : 200 + 300 * im. I cannot say whether the one is bigger than the other, but I can definitely say, whether a number is contained in this or not. I can also say, which units and step size I am using myself.

So let’s say b < 8. Therefore, b - 8 < 0. “<” equals zero for b = 8; “<” equals one for b = 7. Now, “<” itself is smaller than 0. But what if real(“<”) < 0 and imag(“<”) < 0? They do not collide on real and imaginary axe.

< is typically not defined on complex numbers (either in math or programming).

10 Likes

There is no order of complex numbers which doesn’t collide with the sum and product.
(Ninja’d :slight_smile: )

Did you want norm(x) < norm(y)?

3 Likes

What is the tension on the other side - for normally a:step:b step=1, then for complex numbers, step does not solve, but it gives default 0 - but saying it’s 0 (which definitely gives true when x: e^x … operations are symmetric) is also definitely wrong for being 1;

furthermore, for x in complex range datatype:

do something with x without touching other elements.

I don’t think I want to convert the type of my variable

Actually, I don’t want to define everything in my math - I don’t have everything defined in my problem, neither. If it’s undefined, then undefined is a very correct answer.

True.
0/0 results in NaN, where undefined would be the mathematical correct answer. But this is not a math enzyklopedia, its a programming language. So I am fine with getting an error when trying to get an order of complex numbers where it is undefined.

On the other side, you may define your own order by implementing isless(::Complex{Int64}, ::Complex{Int64}). And you have the freedom to return something which correspond to undefined. What would be the benefit?

2 Likes

Don’t define isless for Complex, thats type piracy.

Also, this is completely different from 0/0. It would be ok if,

  1. There’s a standard/convention about the result, or
  2. You return a result that is out of the domain of the normal values (e.g. define isless(::Complex, ::Complex) = NaN)

You can of course define you own comparison function if you want to use it to sort complex numbers in any particular ways.

6 Likes

I think 0 is not 0i, because they are on different axes.

I definitely like 1i < 2i, which implies every ni < mi for n < m, which definitely work for every little function I’m typically using for complex numbers. But, I cannot say a language, which excplicitly states the problem and requires me to get around it, is not syntactically more powerful.

I am not saying that 0/0 is the same as complex numbers don’t have a linear order. What I refering to is, that @vaeli wants a mathematical correct return of undefined, if it is mathematical undefined, and NaN does not have the same meaning as undefined. Or he wants some pragmatic order of complex numbers where the real part is 0.
Thats how I understand OP.

My opinion is, that this an excessive requirement to a programming language, even to a scientific programming language.

If someone needs above requirements and NaN is not enough for whatever reason it should be implemented by that someone. Thats what programming languages are for: implement what you need if it is not already done.

The attitude that something should be in the language by default is something which is not so rare in here the Julia discussions. The reason is, in my opinion, that people expect something like Mathlab (don’t know much about it) or something like RStudio (not just R). They want to put some tools on some data and get results. Which is a view on Julia from a users pespective, not from a programmers view. This is one of the very few aspects of Julia (or more the way Julia is promoted) that I don’t like, the focus on Julia as a toolbox. I want it seen as a general programming language (and not only as a scientific PL!). So much for now off topic, why I answered as I did, ignoring type piracy and so on.

2 Likes

Well I think I solved this one. If e^x is growing to infinity, then indeed, square root of minus one must be infinitely smaller than, say, zero - but it’s a growing function. If complex function is actually a function of growing complexity, then e^x is passing levels of infinity, and as it always comes back as a circle, then e^x, compared to some function, which is infinity even at zero, but also growing in density, must be a function of something, which comes at rate 3/4 back from infinity.

Well working with undefined values is property of datatypes themselves. For example, more advanced numbers in mathematics allow many operations, which are illegal for more simple numbers - so they won’t return the same NaN. Mathematically, there might be a common base principle, but in actuality, you often do only a limited set of operations; for example drawing circle on the screen you only pass points.