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?
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.
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?
Yep, that’s the kind of thing I was thinking of.
Yes. Just like absolute value looks at -1.3 and 1.3 and outputs 1.3
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.
I think to get what you want, you would use 10[sup]|log[sub]10[/sub]x|[/sup]. A logarithm is the same for x vs. 1/x except for the sign.
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.
Thanks guys. I should have thought of using logs (I’ll use the excuse of being under the weather). Honestly, what made me think of this is KenKen puzzles.
Just be careful though, if you use this in Excel or something like that it will balk at an input of 0.
<Formatting problems>
Or negative numbers. I just took log -5 on my calculator and it gave me
(0.698970004336;1.36437635384)
I am not quite sure what that means.
That the logarithm is a complex number: Log10(-5) ~ 0.7 + 1.36 i.
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.
Bolding mine. The absolute value function for real numbers generalizes to magnitudes of complex numbers, or of vectors (of dimension > 1).
I don’t think the “version” the OP proposes has a natural extension beyond the real numbers, does it?
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 p-adic absolute values, but note that |2|[sub]2[/sub] = 1/2 while |1/2|[sub]2[/sub] = 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 so-called p-adic numbers.
Understood. I just find it a bit inelegant.
Cool.
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.
Although it may not have a use that immediately comes to mind, I can think of places where it might be useful. Basically, places where a log transformation would be useful.
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.
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.
With good reason. The function the OP identified doesn’t have a defined value for 0.