Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2018, 02:08 PM
Andy L Andy L is online now
Member
 
Join Date: Oct 2000
Posts: 5,102
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 02:08 PM.
  #2  
Old 03-21-2018, 02:14 PM
scr4 scr4 is offline
Member
 
Join Date: Aug 1999
Location: Alabama
Posts: 14,384
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  
Old 03-21-2018, 02:16 PM
Inigo Montoya Inigo Montoya is online now
Guest
 
Join Date: Mar 2004
Location: On the level, if inclined
Posts: 13,867
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 02:17 PM.
  #4  
Old 03-21-2018, 02:16 PM
Andy L Andy L is online now
Member
 
Join Date: Oct 2000
Posts: 5,102
Quote:
Originally Posted by scr4 View Post
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  
Old 03-21-2018, 02:17 PM
Andy L Andy L is online now
Member
 
Join Date: Oct 2000
Posts: 5,102
Quote:
Originally Posted by Inigo Montoya View Post
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  
Old 03-21-2018, 02:20 PM
Buck Godot Buck Godot is online now
Guest
 
Join Date: Mar 2010
Location: MD outside DC
Posts: 4,581
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  
Old 03-21-2018, 02:24 PM
eschereal eschereal is online now
Guest
 
Join Date: Aug 2012
Location: Frogstar World B
Posts: 13,520
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  
Old 03-21-2018, 02:31 PM
Asympotically fat Asympotically fat is online now
Guest
 
Join Date: Jan 2008
Posts: 3,121
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  
Old 03-21-2018, 02:38 PM
Andy L Andy L is online now
Member
 
Join Date: Oct 2000
Posts: 5,102
Quote:
Originally Posted by Buck Godot View Post
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 View Post
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 View Post
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  
Old 03-21-2018, 02:42 PM
OldGuy OldGuy is offline
Charter Member
 
Join Date: Dec 2002
Location: Very east of Foggybog, WI
Posts: 4,684
Just be careful though, if you use this in Excel or something like that it will balk at an input of 0.
  #11  
Old 03-21-2018, 02:52 PM
Asympotically fat Asympotically fat is online now
Guest
 
Join Date: Jan 2008
Posts: 3,121
<Formatting problems>

Last edited by Asympotically fat; 03-21-2018 at 02:53 PM.
  #12  
Old 03-21-2018, 03:03 PM
eschereal eschereal is online now
Guest
 
Join Date: Aug 2012
Location: Frogstar World B
Posts: 13,520
Quote:
Originally Posted by OldGuy View Post
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  
Old 03-21-2018, 03:18 PM
g8rguy g8rguy is online now
Guest
 
Join Date: Jun 2001
Location: Houston
Posts: 1,465
Quote:
Originally Posted by eschereal View Post
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  
Old 03-21-2018, 03:33 PM
Asympotically fat Asympotically fat is online now
Guest
 
Join Date: Jan 2008
Posts: 3,121
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  
Old 03-21-2018, 03:51 PM
Thudlow Boink Thudlow Boink is online now
Charter Member
 
Join Date: May 2000
Location: Lincoln, IL
Posts: 24,716
Quote:
Originally Posted by Andy L View Post
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  
Old 03-21-2018, 03:55 PM
DPRK DPRK is offline
Guest
 
Join Date: May 2016
Posts: 1,347
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  
Old 03-21-2018, 04:16 PM
Andy L Andy L is online now
Member
 
Join Date: Oct 2000
Posts: 5,102
Quote:
Originally Posted by Asympotically fat View Post
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 View Post
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  
Old 03-21-2018, 04:21 PM
Buck Godot Buck Godot is online now
Guest
 
Join Date: Mar 2010
Location: MD outside DC
Posts: 4,581
Quote:
Originally Posted by Asympotically fat View Post
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  
Old 03-21-2018, 04:21 PM
Chronos Chronos is online now
Charter Member
Moderator
 
Join Date: Jan 2000
Location: The Land of Cleves
Posts: 76,091
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  
Old 03-21-2018, 04:32 PM
Buck Godot Buck Godot is online now
Guest
 
Join Date: Mar 2010
Location: MD outside DC
Posts: 4,581
Quote:
Originally Posted by OldGuy View Post
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  
Old 03-21-2018, 04:35 PM
Thudlow Boink Thudlow Boink is online now
Charter Member
 
Join Date: May 2000
Location: Lincoln, IL
Posts: 24,716
Quote:
Originally Posted by Andy L View Post
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 |ab| gives you the absolute difference between two numbers regardless of which one is larger.

Quote:
Originally Posted by Chronos View Post
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  
Old 03-21-2018, 04:36 PM
Chronos Chronos is online now
Charter Member
Moderator
 
Join Date: Jan 2000
Location: The Land of Cleves
Posts: 76,091
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 04:37 PM.
  #23  
Old 03-21-2018, 04:41 PM
Thudlow Boink Thudlow Boink is online now
Charter Member
 
Join Date: May 2000
Location: Lincoln, IL
Posts: 24,716
Quote:
Originally Posted by Chronos View Post
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  
Old 03-21-2018, 04:45 PM
eschereal eschereal is online now
Guest
 
Join Date: Aug 2012
Location: Frogstar World B
Posts: 13,520
Quote:
Originally Posted by Chronos View Post
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  
Old 03-21-2018, 05:32 PM
Chronos Chronos is online now
Charter Member
Moderator
 
Join Date: Jan 2000
Location: The Land of Cleves
Posts: 76,091
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  
Old 03-21-2018, 05:55 PM
septimus septimus is online now
Guest
 
Join Date: Dec 2009
Location: The Land of Smiles
Posts: 15,809
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  
Old 03-21-2018, 06:22 PM
Manlob Manlob is offline
Guest
 
Join Date: May 2000
Posts: 157
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  
Old 03-21-2018, 06:38 PM
Andy L Andy L is online now
Member
 
Join Date: Oct 2000
Posts: 5,102
Quote:
Originally Posted by Manlob View Post
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  
Old 03-21-2018, 07:03 PM
Ignotus Ignotus is offline
Guest
 
Join Date: Dec 2012
Posts: 1,107
Quote:
Originally Posted by Buck Godot View Post
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  
Old 03-21-2018, 08:27 PM
Chronos Chronos is online now
Charter Member
Moderator
 
Join Date: Jan 2000
Location: The Land of Cleves
Posts: 76,091
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  
Old 03-21-2018, 08:33 PM
Chronos Chronos is online now
Charter Member
Moderator
 
Join Date: Jan 2000
Location: The Land of Cleves
Posts: 76,091
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  
Old 03-21-2018, 08:52 PM
Asympotically fat Asympotically fat is online now
Guest
 
Join Date: Jan 2008
Posts: 3,121
Quote:
Originally Posted by Andy L View Post
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  
Old 03-21-2018, 09:59 PM
gazpacho gazpacho is offline
Guest
 
Join Date: Oct 1999
Posts: 5,656
Quote:
Originally Posted by Asympotically fat View Post
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  
Old 03-22-2018, 04:21 PM
Manlob Manlob is offline
Guest
 
Join Date: May 2000
Posts: 157
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  
Old 03-22-2018, 07:44 PM
Chronos Chronos is online now
Charter Member
Moderator
 
Join Date: Jan 2000
Location: The Land of Cleves
Posts: 76,091
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  
Old 03-23-2018, 07:37 AM
ftg ftg is offline
Guest
 
Join Date: Feb 2001
Location: Not the PNW :-(
Posts: 16,410
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?
Reply

Bookmarks

Thread Tools
Display Modes

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 Jump


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

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.

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

Send comments about this website to: webmaster@straightdope.com

Terms of Use / Privacy Policy

Advertise on the Straight Dope!
(Your direct line to thousands of the smartest, hippest people on the planet, plus a few total dipsticks.)

Publishers - interested in subscribing to the Straight Dope?
Write to: sdsubscriptions@chicagoreader.com.

Copyright 2018 STM Reader, LLC.

 
Copyright © 2017