import math def cantorPair((x,y)): return int(0.5*(x+y)*(x+y+1)+y) def cantorPairInverse(z): w = math.floor(0.5*(math.sqrt(8*z+1)-1)) t = (w*w + w)/2 y = int(z - t) x = int(w - y) return (x,y) def cantorTuple(t): # return the index in the countable set return 0 def cantorTupleInverse(z): # return the n-tuple return (0,0) def main(): print("cantorPair((47,32)) = " + str(cantorPair((47,32)))) print("cantorPairInverse(3192) = " + str(cantorPairInverse(3192))) print("cantorPair((2,3)) = " + str(cantorPair((2,3)))) print("cantorPairInverse(18) = " + str(cantorPairInverse(18))) main()