# 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:** 16\
**Page:** 2

<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, 9:35pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/21 "2018-03-21T21:35:48Z")

</div>

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

> [@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(x[sup]2[/sup]) it need not be considered a piecewise function.

---

<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:36pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/22 "2018-03-21T21:36:16Z")

</div>

And there are two different interpretations for what he means for negative arguments.

EDIT:

> [@](#):
>
> Depends on how you define it. If you define it as sqrt(x[sup]2[/sup]) 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.

---

<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, 9:41pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/23 "2018-03-21T21:41:42Z")

</div>

> [@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(a[sup]2[/sup]+b[sup]2[/sup]). Is there something piecewise about that?

---

<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, 9:45pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/24 "2018-03-21T21:45:40Z")

</div>

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

---

<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, 10:32pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/25 "2018-03-21T22:32:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [March 21, 2018, 10:55pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/26 "2018-03-21T22:55:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Manlob](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Manlob](https://boards.straightdope.com/u/Manlob)\
**Post date:** [March 21, 2018, 11:22pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/27 "2018-03-21T23:22:33Z")

</div>

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

---

<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, 11:38pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/28 "2018-03-21T23:38:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ignotus](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Ignotus](https://boards.straightdope.com/u/Ignotus)\
**Post date:** [March 22, 2018, 12:03am UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/29 "2018-03-22T00:03:27Z")

</div>

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

---

<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 22, 2018, 1:27am UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/30 "2018-03-22T01:27:30Z")

</div>

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

---

<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 22, 2018, 1:33am UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/31 "2018-03-22T01:33:30Z")

</div>

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

---

<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 22, 2018, 1:52am UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/32 "2018-03-22T01:52:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gazpacho](https://avatars.discourse-cdn.com/v4/letter/g/6f9a4e/32.png) [@gazpacho](https://boards.straightdope.com/u/gazpacho)\
**Post date:** [March 22, 2018, 2:59am UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/33 "2018-03-22T02:59:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Manlob](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Manlob](https://boards.straightdope.com/u/Manlob)\
**Post date:** [March 22, 2018, 9:21pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/34 "2018-03-22T21:21:03Z")

</div>

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

---

<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 23, 2018, 12:44am UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/35 "2018-03-23T00:44:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [March 23, 2018, 12:37pm UTC](https://boards.straightdope.com/t/generalization-of-absolute-value/810981/36 "2018-03-23T12:37:46Z")

</div>

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[sup]2[/sup]+1/X[sup]2[/sup])

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?

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