wrote purity generating function for arbitrary dimensions