Remember Me?

 Straight Dope Message Board Remember Me?

#1
03-21-2018, 03:08 PM
 Andy L Member Join Date: Oct 2000 Posts: 5,674
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; 03-21-2018 at 03:08 PM.
#2
03-21-2018, 03:14 PM
 scr4 Member Join Date: Aug 1999 Location: Alabama Posts: 15,009
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
03-21-2018, 03:16 PM
 Inigo Montoya Member Join Date: Mar 2004 Location: On the level, if inclined Posts: 14,973
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; 03-21-2018 at 03:17 PM.
#4
03-21-2018, 03:16 PM
 Andy L Member Join Date: Oct 2000 Posts: 5,674
Quote:
 Originally Posted by scr4 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.
Yep, that's the kind of thing I was thinking of.
#5
03-21-2018, 03:17 PM
 Andy L Member Join Date: Oct 2000 Posts: 5,674
Quote:
 Originally Posted by Inigo Montoya 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?
Yes. Just like absolute value looks at -1.3 and 1.3 and outputs 1.3
#6
03-21-2018, 03:20 PM
 Buck Godot Guest Join Date: Mar 2010 Location: MD outside DC Posts: 5,228
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
03-21-2018, 03:24 PM
 eschereal Guest Join Date: Aug 2012 Location: Frogstar World B Posts: 15,067
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
03-21-2018, 03:31 PM
 Asympotically fat Guest Join Date: Jan 2008 Posts: 3,158
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
03-21-2018, 03:38 PM
 Andy L Member Join Date: Oct 2000 Posts: 5,674
Quote:
 Originally Posted by Buck Godot 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.
Quote:
 Originally Posted by eschereal 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.
Quote:
 Originally Posted by Asympotically fat 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.
#10
03-21-2018, 03:42 PM
 OldGuy Charter Member Join Date: Dec 2002 Location: Very east of Foggybog, WI Posts: 5,055
Just be careful though, if you use this in Excel or something like that it will balk at an input of 0.
#11
03-21-2018, 03:52 PM
 Asympotically fat Guest Join Date: Jan 2008 Posts: 3,158
<Formatting problems>

Last edited by Asympotically fat; 03-21-2018 at 03:53 PM.
#12
03-21-2018, 04:03 PM
 eschereal Guest Join Date: Aug 2012 Location: Frogstar World B Posts: 15,067
Quote:
 Originally Posted by OldGuy Just be careful though, if you use this in Excel or something like that it will balk at an input of 0.
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.
#13
03-21-2018, 04:18 PM
 g8rguy Guest Join Date: Jun 2001 Location: Houston Posts: 1,491
Quote:
 Originally Posted by eschereal 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.
#14
03-21-2018, 04:33 PM
 Asympotically fat Guest Join Date: Jan 2008 Posts: 3,158
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
03-21-2018, 04:51 PM
 Thudlow Boink Charter Member Join Date: May 2000 Location: Lincoln, IL Posts: 25,874
Quote:
 Originally Posted by Andy L Is there an equivalent of absolute value for reciprocals? The absolute value function outputs the magnitude of a real number
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?
#16
03-21-2018, 04:55 PM
 DPRK Guest Join Date: May 2016 Posts: 2,282
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|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 so-called p-adic numbers.
#17
03-21-2018, 05:16 PM
 Andy L Member Join Date: Oct 2000 Posts: 5,674
Quote:
 Originally Posted by Asympotically fat 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.
Understood. I just find it a bit inelegant.

Quote:
 Originally Posted by DPRK 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|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 so-called p-adic numbers.
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.
#18
03-21-2018, 05:21 PM
 Buck Godot Guest Join Date: Mar 2010 Location: MD outside DC Posts: 5,228
Quote:
 Originally Posted by Asympotically fat However as noted such a function doesn't have an obvious use.
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.
#19
03-21-2018, 05:21 PM
 Chronos Charter Member Moderator Join Date: Jan 2000 Location: The Land of Cleves Posts: 80,080
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
03-21-2018, 05:32 PM
 Buck Godot Guest Join Date: Mar 2010 Location: MD outside DC Posts: 5,228
Quote:
 Originally Posted by OldGuy Just be careful though, if you use this in Excel or something like that it will balk at an input of 0.
With good reason. The function the OP identified doesn't have a defined value for 0.
#21
03-21-2018, 05:35 PM
 Thudlow Boink Charter Member Join Date: May 2000 Location: Lincoln, IL Posts: 25,874
Quote:
 Originally Posted by Andy L 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.
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.

Quote:
 Originally Posted by Chronos I understand finding piecewise functions inelegant, but ultimately, the absolute value function is itself a piecewise function.
Depends on how you define it. If you define it as sqrt(x2) it need not be considered a piecewise function.
#22
03-21-2018, 05:36 PM
 Chronos Charter Member Moderator Join Date: Jan 2000 Location: The Land of Cleves Posts: 80,080
And there are two different interpretations for what he means for negative arguments.

EDIT:
Quote:
 Depends on how you define it. If you define it as sqrt(x2) it need not be considered a piecewise function.
Only if you've already decreed that the square root must be positive, which actually requires an even less elegant piecewise function.

Last edited by Chronos; 03-21-2018 at 05:37 PM.
#23
03-21-2018, 05:41 PM
 Thudlow Boink Charter Member Join Date: May 2000 Location: Lincoln, IL Posts: 25,874
Quote:
 Originally Posted by Chronos Only if you've already decreed that the square root must be positive, which actually requires an even less elegant piecewise function.
How so?

I'm still thinking of the generalization of absolute value/magnitude to complex numbers, where |a+bi| = sqrt(a2+b2). Is there something piecewise about that?
#24
03-21-2018, 05:45 PM
 eschereal Guest Join Date: Aug 2012 Location: Frogstar World B Posts: 15,067
Quote:
 Originally Posted by Chronos 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.
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.
#25
03-21-2018, 06:32 PM
 Chronos Charter Member Moderator Join Date: Jan 2000 Location: The Land of Cleves Posts: 80,080
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.
#26
03-21-2018, 06:55 PM
 septimus Guest Join Date: Dec 2009 Location: The Land of Smiles Posts: 17,830
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
03-21-2018, 07:22 PM
 Manlob Guest Join Date: May 2000 Posts: 169
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:

x/2 +1/(2x) + sqrt( x^2/4 +1/(4x^2) - 1/2 ) = x/2 + 1/(2x) + | x/2 - 1/(2x)|
#28
03-21-2018, 07:38 PM
 Andy L Member Join Date: Oct 2000 Posts: 5,674
Quote:
 Originally Posted by Manlob 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: x/2 +1/(2x) + sqrt( x^2/4 +1/(4x^2) - 1/2 ) = x/2 + 1/(2x) + | x/2 - 1/(2x)|
Nice. Thanks.
#29
03-21-2018, 08:03 PM
 Ignotus Guest Join Date: Dec 2012 Posts: 1,241
Quote:
 Originally Posted by Buck Godot 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.
It's involved, sorta, in that procedure called "error analysis by logarithmic differentiation" we used to do in college physics...
#30
03-21-2018, 09:27 PM
 Chronos Charter Member Moderator Join Date: Jan 2000 Location: The Land of Cleves Posts: 80,080
Quote:
 The implication, since we are looking for the larger of a number of and its multiplicative inverse,...
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)?
#31
03-21-2018, 09:33 PM
 Chronos Charter Member Moderator Join Date: Jan 2000 Location: The Land of Cleves Posts: 80,080
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).
#32
03-21-2018, 09:52 PM
 Asympotically fat Guest Join Date: Jan 2008 Posts: 3,158
Quote:
 Originally Posted by Andy L Understood. I just find it a bit inelegant.
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
03-21-2018, 10:59 PM
 gazpacho Guest Join Date: Oct 1999 Posts: 5,680
Quote:
 Originally Posted by Asympotically fat 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.
#34
03-22-2018, 05:21 PM
 Manlob Guest Join Date: May 2000 Posts: 169
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
03-22-2018, 08:44 PM
 Chronos Charter Member Moderator Join Date: Jan 2000 Location: The Land of Cleves Posts: 80,080
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
03-23-2018, 08:37 AM
 ftg Guest Join Date: Feb 2001 Location: Not the PNW :-( Posts: 18,124
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(X2+1/X2)

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?

 Bookmarks

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Main     About This Message Board     Comments on Cecil's Columns/Staff Reports     General Questions     Great Debates     Elections     Cafe Society     The Game Room     Thread Games     In My Humble Opinion (IMHO)     Mundane Pointless Stuff I Must Share (MPSIMS)     Marketplace     The BBQ Pit

All times are GMT -5. The time now is 03:29 PM.

 -- Straight Dope v3.7.3 -- Sultantheme's Responsive vB3-blue Contact Us - Straight Dope Homepage - Archive - Top

Send questions for Cecil Adams to: cecil@straightdope.com