Hacker News new | ask | show | jobs
by _emna 942 days ago
Sorry, can you explain this? To me, it makes sense to define abs(x) = sqrt(x^2) i.e. ignoring the negative solution enforces the positive result. Using that definition, abs(i+1) = sqrt((i+1)^2) = sqrt(i^2 + 2i + 1) = sqrt(-1 + 2i + 1) = sqrt(2i) != sqrt(2). The second example seems off in the same way (i.e. the answer should be sqrt(8i) instead of sqrt(8)). Am I missing something? Also, abs(i+2) = sqrt((i+2)^2) = sqrt(i^2 + 4i + 4) = sqrt(-1 + 4i + 4) = sqrt(4i + 3) which doesnt seem to follow the pattern your son described.

Also, just to point out that my understanding of absolute value is different than your sons. Thats not to say one is right and another is wrong, but there are often different ways of seeing the same thing. I would imagine that LLMs would similarly see it a different way. Another example of this is people defining PI by its relation to the circumference of a circle. Theres nothing wrong with such a definition, but its certainly not the only possible definition.

7 comments

> To me, it makes sense to define abs(x) = sqrt(x^2) i.e. ignoring the negative solution enforces the positive result.

Why does this make sense to you? You have some notion of what an absolute value should be, on an intuitive or conceptual level, and the mathematical definition you give is consistent with that (in the one dimensional case).

Now taking this valid definition for the 1-d case and generalizing that to higher dimensions is where you run into problems.

Instead, you can go back to the conceptual idea of the absolute value and generate a definition for higher dimensional cases from there.

Interpreting absolute value as the distance from the origin yields the same concrete definition of abs(x) = sqrt(x^2) for the 1-d case, but generalizes better to higher dimensions: abs( (x,y) ) = sqrt(x^2 + y^2) for the 2-d case equivalent to complex numbers.

> Why does this make sense to you? You have some notion of what an absolute value should be, on an intuitive or conceptual level, and the mathematical definition you give is consistent with that (in the one dimensional case).

In my mind abs(x) = x*sign(x) which is why the above formulation seems correct. This formulation is useful, for example, in formulating reflections.

> Instead, you can go back to the conceptual idea of the absolute value and generate a definition for higher dimensional cases from there.

This is an interesting idea...how would you define sign(x) in a higher dimension? Wouldnt sign in a higher dimension be a component-wise function? E.g. the reflection would happen on one axis but not the other.

> Interpreting absolute value as the distance from the origin

This seems to make sense in that it is a different interpretation of abs which seems simpler than reflection in higher dimensions, but seems like a different definition.

I know that there are applications of complex numbers in real systems. In such systems, the complex definition seems to not be as valuable. E.g. if I'm solving a laplace transform, the real number definition seems more applicable than the complex number definition, right?

I've asked wolfram alpha to solve the equation and it lists both answers: one using the formulation of sqrt(x^2) and the other using sqrt(re(x)^2 + im(x)^2) so it seems like there is merit to both...

I suppose in the laplace example, we are actually operating in one dimension and the imaginary component is approximating something non-real, but doesnt actually exist. I.e. any real/observable effect only happens when the imaginary component disappears meaning that this is still technically one dimension. So, since we're still in one dimension, the one dimensional formula still applies. Is that correct?

Your explanation has been the most helpful though, thanks.

> In my mind abs(x) = x * sign(x) which is why the above formulation seems correct.

> This is an interesting idea...how would you define sign(x) in a higher dimension?

You could think of the sign as the direction. In the 1-d case, you only have two directions. Positive sign means to the right of the origin, negative sign means to the left of the origin. But in higher dimensional case, you don't get a higher count of directions, instead direction becomes a space.

To see this analogy we can rewrite your abs(x) = x * sign(x) as x = abs(x) * sign(x). (Because 1/sign(x) = sign(x) except at 0, where the two equations agree anyway.)

Now consider that in higher dimensions, we can write x = ||x||*(x/||x||) for any vector x, where ||x|| denotes the magnitude and the term x/||x|| is the unit vector in direction of x. This term then plays the role of the sign.

A simple reflection can then still be done by multiplying this direction term with -1, which in the 2d case reflects at a line through the origin and perpendicular to the vector.

I can't comment on the Laplace transform, it's been too long since I used that.

> abs(x) = x*sign(x)

True in 1 dimension, but not in higher dimensions, because, as you say:

> how would you define sign(x) in a higher dimension?

abs(x) is generally defined as distance of x from zero.

The fact that sqrt(x^2) or x*sign(x) happen to give the same result in 1 dimension doesn't necessarily imply that they can be applied in higher dimensions as-is to result in abs(x) with the same meaning. Although sqrt(x^2) is close, but the way to generalize it is sqrt(sum(x[i]^2)).

The absolute value of a complex number is defined in a different way than that of a real number. For complex number z it is sqrt(Re(z)^2 + Im(z)^2). GP’s examples are correct, I don’t think there’s any ambiguity there.

https://en.m.wikipedia.org/wiki/Absolute_value

That definition of abs has merit. In some spaces we are able first to define only an “inner product” between elements p(a, b) and then follow on by naming the length of an element to be sqrt(p(a, a)).

One trick about that inner product is that it need not be perfectly symmetric. To make it work on complex numbers we realize that we have to define it like p(a,b) = a . conj(b) where the . is normal multiplication and the conjugate operation reflects a complex number over the real line.

Now sqrt(p(i+1, i+1)) is sqrt((i+1) . (-i+1)) = sqrt(-i^2 + i - i + 1) = sqrt(2).

I’m skipping over a lot but I wanted to gesture toward where your intuition matches some well known concepts so that you could dive in more deeply. Also wanted to mention the conjugation trick to make your example work!

No, there is just one definition, and it's his son's: https://en.m.wikipedia.org/wiki/Absolute_value#Complex_numbe...
The article you linked literally says that there are two definitions: one for real numbers and another for complex numbers. Thanks for the info.
That’s not what it says. It says that there is a single definition that can be generalized to both real and complex numbers.

A special cases of the general definition where im(z)==0 yields an expression where some parts are multiplied by zero, and can then be omitted entirely.

This means that there is one definition. You can mentally ignore some parts of this when dealing with reals.

There is one definition: the distance to 0. There are several (more than two) different ways to calculate it in different situations.
Have you tested your proposed function against i?

abs(i)

= sqrt(i^2)

= sqrt(-1)

= i

Now, i != 1... so clearly either the abs function you have in mind here is doing something that isn't quite aligned with the goal. If we assume that the goal of the absolute function is to always produce positive real numbers, the function is missing something to deal with imaginary components.

I'm not sure, but based on these cases so far, maybe you just need to "drop the i" in the same way as you need to "drop the negative" in the case of non-imaginary components. Now, "drop the i" is not an actual function so maybe there is something else that you can think of?

EDIT:

Maybe could do this(works for x = i at least...):

abs(x) = sqrt(sqrt((x^2)^2)

Now.. how about quaternions...

> Also, just to point out that my understanding of absolute value is different than your sons. Thats not to say one is right and another is wrong, but there are often different ways of seeing the same thing.

There is definitely a right and wrong answer for this, it's not a matter of opinion. There's two problems with your answer -- one is that it doesn't have a unique answer, the other is that it doesn't produce a real value, both of which are fairly core to the concept of a distance (or magnitude or norm), which the absolute value is an example of.

He's talking about distance in two dimensions with real numbers on one axis and complex on the other.