The Polysign Distance Function
The native distance function was first exposed by Jonathan Doolin in a USENET
A four-signed value
- a + b * c # d
sqrt( aa + bb + cc + dd - (2/3)(ab + ac + ad + bc + bd + cd)) .
Likewise a three-signed value
- a + b * c
sqrt( aa + bb + cc - ab - ac - bc )
from the origin.
For two-signed values
- a + b
the distance is
sqrt( aa + bb - 2ab ).
The following C++ algorithm provides the distance for any sign level
double nSigned::Magnitude() const
double d = 0;
double fac = - 1.0 / ( n - 1 );
for( int i = 0; i < n; i++ )
for( int j = 0; j < n; j++ )
if( i == j ) d += x[i] * x[j];
else d += fac * x[i] * x[j];
where n is the signature and x[i] are
This distance function exactly matches the standard Cartesian distance
when the polysign value is transformed.
Back to Polysigned Numbers