Compare fractions a/b and b/a

38 Views Asked by At

I'm trying to implement a mathematical method for calculation of injustice. The formula depends on two variables $a>=1$ and $b>=1$ and returns a fraction $a/b$.

$a/b=1$ indicates justice. If $a/b<1$ the injustice is to your advantage. If $a/b>1$ the injustice is to your disadvantage.

Now I would like to set aside advantage/disadvantage and only calculate the size of the injustice. I'm having trouble figuring out an easy way to get the same result for $a/b$ as $b/a$.

Anyone have any idea of how I can do this?

2

There are 2 best solutions below

1
On BEST ANSWER

As noted in the comments:

The function $$F\left(\frac ab\right)=|\log \frac ab|=|\log a - \log b|$$

gets the job done.

It is easy to see that $$F\left(\frac ab\right)=F\left(\frac ba\right)$$ and that $$F\left(\frac ab\right)=0\iff a= b$$ which appear to be the two desired properties.

0
On

Perhaps simpler than logarithms would be to define the injustice to be the larger of $a/b$ and $b/a$.