phipt function

Distances between communities, auxiliary functions