Is there a meaningful kind of difference "$|a-b|$" in modular arithmetic?
For example, in mod $12$, we would like to have $|0-11|= 1$ and $|0-1| = 1$.
Is there a meaningful kind of difference "$|a-b|$" in modular arithmetic?
For example, in mod $12$, we would like to have $|0-11|= 1$ and $|0-1| = 1$.
Copyright © 2021 JogjaFile Inc.
In most cases this is a wrong question to ask, because comparison is not a useful concept in modular arithmetic. Modulo $n$, all numbers are greater than 0 and all numbers are less than 0.
That said, if you did find a context in which the sort of function you are talking about was useful, I would say that all you would have to do is find the least non-negative value of $x$ such that $a-b-x$ is a multiple of the modulus, and the least non-negative value of $x$ such that $b-a-x$ is a multiple of the modulus (or $a-b+x$, it comes to the same thing). Then pick the smaller of the two numbers you have found.