HI sid, what formula are you thinking of; you already have countless metrics available in the Node.
You might be able to recreate a Voronoi Texture, with a crazy custom distance function, via OSL, but that’s way beyond my capabilities. The other option would be to download blender’s source code and do the same in C/C++. That has the advantage that you can reuse part of the code for the Voronoi.