Question

This might seem a little strange, but I'm trying to extend a number of arithmetic concepts to a geometric space and I'm having no shortage of stopping blocks. The specific issue this time is coming up with an equivalent of a least-square metric for the geometric space.

For instance squaring has this feature arithmetically since the arithmetic inverse is just negation. In code:

def arithmetically_symmetric(a):
    return a**2

arithmetically_symmetric(a) == arithmetically_symmetric(-a)
>>> True
arithmetically_symmetric(a) == arithmetically_symmetric(b)
>>> False

In a geometric space however, the inverse is inversion, and for the life of me I can't figure out a way to do this without just having some kind of case statement. Basically I'm looking for a function that working like this:

geometrically_symmetric(a) == geometrically_symmetric(1/a)
>>> True
geometrically_symmetric(a) == geometrically_symmetric(b)
>>> False

The last condition is added so that the trivial solution of:

def geometrically_symmetric(a):
    return a * 1/a

Isn't an option.

Specifically I'm looking for a solutions that's NOT:

def geometrically_symmetric(a):
    if a < 1:
        return 1/a
    return a

Because my primary complaint here is theoretical rather than practical.

Was it helpful?

Solution

If you only need it to work on positive numbers, this is easy:

def gs(a):
    return a**2 + (1/a**2)

That result is shared by any positive number with its own multiplicative inverse, and with no other positive number. For example, gs(2) == gs(0.5) == 4.25.


Unfortunately, it's also shared with its arithmetic inverse: gs(2) == gs(0.5) == gs(-2) == gs(-0.5) == 4.25.

But we can fix that just by copying the sign:

def gs(a):
    return (a**2 + (1/a**2)) * abs(a)/a

Now, gs(2) == gs(0.5) == 4.25 != gs(-2) == gs(0.5) == -4.25.

If you don't like the abs because there's a hidden if in there… well, there isn't. Sticking with floats, you can obviously do a**2**.5.


So that gets us all non-zero floats. And zero is obviously outside the domain, because gs(0) should be equal to gs(1/0), which is not a number.

It still doesn't work for complex numbers, however—gs(i) == 2i == gs(-1/i), but gs(1/i) == -2i == gs(-i). For that, you just need multiply by the conjugate instead of squaring.

OTHER TIPS

How about the square of the logarithm? Something like

import math

def geometrically_symmetric(a):
    x = math.log(a)
    return x*x

geometrically_symmetric(2.) == geometrically_symmetric(.5)   # True

geometrically_symmetric(2.) == geometrically_symmetric(.6)   # False
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top