The math of connecting galaxies in an efficient way