Ah, this makes sense. You’re looking for a sort of “absolute ratio” of two different numbers, analogous to how |a–b| gives you the absolute difference between two numbers regardless of which one is larger.
Depends on how you define it. If you define it as sqrt(x[sup]2[/sup]) it need not be considered a piecewise function.
I’m still thinking of the generalization of absolute value/magnitude to complex numbers, where |a+bi| = sqrt(a[sup]2[/sup]+b[sup]2[/sup]). Is there something piecewise about that?
Absolute value is not necessarily piecewise. On a computer, using FP numbers, absolute value is simply signbit = 0. If binary integers are involved, then yes, there is a conditional, but binary integers cannot express fractions.
While using logs does look more elegant, in terms of computation time it is hugely more costly. For a few values, that cost is minimal, but with more values it can add up more quickly. But elegance can sometimes yield better performance.
Look instead at the generalization of sqrt() itself to complex numbers. sqrt() is, fundamentally, a two-valued function. We pretend that it’s single-valued by taking only the positive solution and throwing away the negative one, which seems straightforward when you’re dealing with only real numbers. But when you try to extend that to complex numbers, you realize just how straightforward it isn’t.
Writing |log(x)| is a simple way.
Alternatively it might be convenient to write θ=tan(x) and then speak of the larger or “appropriate” tangent of the θ-triangle.
The implication, since we are looking for the larger of a number of and its multiplicative inverse, is that this function is defined for real non-zero numbers. You could use:
It’s still not clear to me if this is precisely what we want, or of we want the one that has a larger absolute value.
That is to say, -5 and -1/5 should both give the same value. But is the value they should both give -1/5 (the greater of the two), or -5 (the greater absolute value of the two)?
Oh, and along the lines of Manlob’s (efficient and elegant) suggestion, it seems to me that once one has any one piecewise function, one can use it to define any other piecewise function (to within some possible single-point problems). For instance, the Heaviside function can be defined in terms of |x| as H(x) = (x/|x| + 1)/2. And any piecewise function can be defined in terms of the Heaviside function (in fact, that’s its entire purpose).
Elegance is subjective, but the identity function and the reciprocal function are much simpler to define than exponentiation and a logarithmic function, so though it may not appear it, the piecewise definition is more elegant as it is the most simple and a definition using the log function is inelegant as it requires extraneous defintitions.
I totally agree with this. sqrt(x*2) is much more complicated than absolute value. Sqrt is a iterative process getting a better and better approximation of the value where changeing the sign is either setting a single bit or a compare then flipping all the bits and adding 1 depending on how the number is represented.
My scientific calculator does not have an absolute value function. I don’t know what I would do if had to do absolute values manually. Fortunately the calculator has x^2 and sqrt(x).
If you’re doing it one step at a time, then you look at the screen and hit the [+/-] button if it’s negative. If you’re programming it, then you slip in a line that says “if x < 0 then x = -x”, or however you phrase that in your calculator’s programming language.
This is unquestionably not what the OP is looking for, but a useful “magnitude” function that is symmetric for X and 1/X can be generated by the distance of the point (X,1/X) to the origin.
sqrt(X[sup]2[/sup]+1/X[sup]2[/sup])
You can “norm” this if you want 1 for X=1. Note that it also works for negative values.
But not for X=0. Speaking of which, what’s the OP’s position on this?