FAQ 
Calendar 


#1




Generalization of absolute value
Is there an equivalent of absolute value for reciprocals? The absolute value function outputs the magnitude of a real number; another way of saying this is that the absolute value function picks the larger of the input number and its additive inverse. Is there a similar function for multiplicative inverses  so if the input was 1/2 or 2, you'd get 2 as the output?
Last edited by Andy L; 03212018 at 02:08 PM. 
#2




Do you mean:
if (x > 1) then return(x) else return(1/x) ? I've never heard of anything like that, and don't see when that would be useful. 
#3




So you're looking for something that would look at 1/5 and 5, or 1/3 and 3 and spit out...what: 5 or 3?
__________________
Y'all are just too damned serious. Lighten up. Last edited by Inigo Montoya; 03212018 at 02:17 PM. 
#4




Yep, that's the kind of thing I was thinking of.



#5




Yes. Just like absolute value looks at 1.3 and 1.3 and outputs 1.3

#6




I don't think that there is a named function that does what you describe, but you can create one using logs, exponentials and the absolute value function.
f(x)=exp(ln(x)) will give you what you want. the ln function will turn your multiplicative inverse into an additive inverse, then you apply the absolute value and the take the exponential to undo the log. 
#7




I think to get what you want, you would use 10^{log10x}. A logarithm is the same for x vs. 1/x except for the sign.

#8




Of course such a function exists and you don't need to create it using logs, it's perfectly correct to define it piecewise. However as noted such a function doesn't have an obvious use.

#9




Quote:
Quote:



#10




Just be careful though, if you use this in Excel or something like that it will balk at an input of 0.

#11




<Formatting problems>
Last edited by Asympotically fat; 03212018 at 02:53 PM. 
#12




Quote:
(0.698970004336;1.36437635384)I am not quite sure what that means. 
#13




That the logarithm is a complex number: Log10(5) ~ 0.7 + 1.36 i.

#14




Honestly, the point I was trying to make is logs are an unneccessary side street, you don't need them to define a function that does what the OP wants. You can define functions piecewise in Excel even if you want.



#15




Quote:
I don't think the "version" the OP proposes has a natural extension beyond the real numbers, does it? 
#16




Not quite what was described in the OP, the more common generalization of absolute value (as far as such things are common, but applications do crop up) are padic absolute values, but note that 2_{2} = 1/2 while 1/2_{2} = 2, that is, it is large powers of p which count for a small absolute value. Also (this is kind of the point) this does not work with real numbers, rather with socalled padic numbers.

#17




Quote:
Quote:
The situation that prompted this question was KenKen puzzles, where you sometimes are looking for pairs of numbers that have a ratio of (say) 2, or 3, or a difference of (say) 1, 2, 3 or 4  but the order of the numbers doesn't matter. 
#18




Quote:
Say for example I've got to players one who scored X and one who scored Y, and I find for some reason that a good metric to represent the difference between their abilities is to look at X/Y, but I want to do it in such a way that is symmetric between the two players. For that application this function is exactly what you need. 
#19




I understand finding piecewise functions inelegant, but ultimately, the absolute value function is itself a piecewise function. If it looks more elegant, that really just means that we're more used to its inelegance.



#20




With good reason. The function the OP identified doesn't have a defined value for 0.

#21




Quote:
Depends on how you define it. If you define it as sqrt(x^{2}) it need not be considered a piecewise function. 
#22




And there are two different interpretations for what he means for negative arguments.
EDIT: Quote:
Last edited by Chronos; 03212018 at 04:37 PM. 
#23




Quote:
I'm still thinking of the generalization of absolute value/magnitude to complex numbers, where a+bi = sqrt(a^{2}+b^{2}). Is there something piecewise about that? 
#24




Quote:
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. 


#25




Look instead at the generalization of sqrt() itself to complex numbers. sqrt() is, fundamentally, a twovalued function. We pretend that it's singlevalued 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.

#26




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. 
#27




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 nonzero numbers. You could use:
x/2 +1/(2x) + sqrt( x^2/4 +1/(4x^2)  1/2 ) = x/2 + 1/(2x) +  x/2  1/(2x) 
#28




Nice. Thanks.

#29




Quote:



#30




Quote:
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)? 
#31




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 singlepoint 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).

#32




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.

#33




Quote:

#34




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).



#35




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.

#36




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^{2}+1/X^{2}) 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? 
Reply 
Thread Tools  
Display Modes  

