# Generalization of absolute value

**URL:** <https://boards.straightdope.com/t/generalization-of-absolute-value/810981>\
**Category:** Factual Questions\
**Created:** [March 21, 2018, 7:08pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981 "2018-03-21T19:08:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_L](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Andy\_L](https://boards.straightdope.com/u/Andy_L)\
**Post date:** [March 21, 2018, 7:08pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/1 "2018-03-21T19:08:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![scr4](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@scr4](https://boards.straightdope.com/u/scr4)\
**Post date:** [March 21, 2018, 7:14pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/2 "2018-03-21T19:14:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Inigo\_Montoya](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/inigo_montoya/32/124_2.png) [@Inigo\_Montoya](https://boards.straightdope.com/u/Inigo_Montoya)\
**Post date:** [March 21, 2018, 7:16pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/3 "2018-03-21T19:16:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Andy\_L](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Andy\_L](https://boards.straightdope.com/u/Andy_L)\
**Post date:** [March 21, 2018, 7:16pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/4 "2018-03-21T19:16:50Z")

</div>

> [@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.

---

<div class="post-metadata">

**Author:** ![Andy\_L](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Andy\_L](https://boards.straightdope.com/u/Andy_L)\
**Post date:** [March 21, 2018, 7:17pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/5 "2018-03-21T19:17:51Z")

</div>

> [@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

---

<div class="post-metadata">

**Author:** ![Buck\_Godot](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/buck_godot/32/6573_2.png) [@Buck\_Godot](https://boards.straightdope.com/u/Buck_Godot)\
**Post date:** [March 21, 2018, 7:20pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/6 "2018-03-21T19:20:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eschereal](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eschereal/32/18939_2.png) [@eschereal](https://boards.straightdope.com/u/eschereal)\
**Post date:** [March 21, 2018, 7:24pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/7 "2018-03-21T19:24:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Asympotically\_fat](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Asympotically\_fat](https://boards.straightdope.com/u/Asympotically_fat)\
**Post date:** [March 21, 2018, 7:31pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/8 "2018-03-21T19:31:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andy\_L](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Andy\_L](https://boards.straightdope.com/u/Andy_L)\
**Post date:** [March 21, 2018, 7:38pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/9 "2018-03-21T19:38:00Z")

</div>

> [@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.

> [@eschereal](#):
>
> 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.

> [@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.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [March 21, 2018, 7:42pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/10 "2018-03-21T19:42:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Asympotically\_fat](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Asympotically\_fat](https://boards.straightdope.com/u/Asympotically_fat)\
**Post date:** [March 21, 2018, 7:52pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/11 "2018-03-21T19:52:27Z")

</div>

\<Formatting problems\>

---

<div class="post-metadata">

**Author:** ![eschereal](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eschereal/32/18939_2.png) [@eschereal](https://boards.straightdope.com/u/eschereal)\
**Post date:** [March 21, 2018, 8:03pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/12 "2018-03-21T20:03:36Z")

</div>

> [@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.

---

<div class="post-metadata">

**Author:** ![g8rguy](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@g8rguy](https://boards.straightdope.com/u/g8rguy)\
**Post date:** [March 21, 2018, 8:18pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/13 "2018-03-21T20:18:17Z")

</div>

> [@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_.

---

<div class="post-metadata">

**Author:** ![Asympotically\_fat](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Asympotically\_fat](https://boards.straightdope.com/u/Asympotically_fat)\
**Post date:** [March 21, 2018, 8:33pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/14 "2018-03-21T20:33:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Thudlow\_Boink](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/thudlow_boink/32/320_2.png) [@Thudlow\_Boink](https://boards.straightdope.com/u/Thudlow_Boink)\
**Post date:** [March 21, 2018, 8:51pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/15 "2018-03-21T20:51:48Z")

</div>

> [@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?

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [March 21, 2018, 8:55pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/16 "2018-03-21T20:55:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andy\_L](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Andy\_L](https://boards.straightdope.com/u/Andy_L)\
**Post date:** [March 21, 2018, 9:16pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/17 "2018-03-21T21:16:04Z")

</div>

> [@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.

> [@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|[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.

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.

---

<div class="post-metadata">

**Author:** ![Buck\_Godot](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/buck_godot/32/6573_2.png) [@Buck\_Godot](https://boards.straightdope.com/u/Buck_Godot)\
**Post date:** [March 21, 2018, 9:21pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/18 "2018-03-21T21:21:11Z")

</div>

> [@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.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [March 21, 2018, 9:21pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/19 "2018-03-21T21:21:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Buck\_Godot](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/buck_godot/32/6573_2.png) [@Buck\_Godot](https://boards.straightdope.com/u/Buck_Godot)\
**Post date:** [March 21, 2018, 9:32pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/20 "2018-03-21T21:32:37Z")

</div>

> [@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.

[Next page](https://boards.straightdope.com/t/generalization-of-absolute-value/810981.md?page=2)
