Permutation invariant functions: statistical tests, density estimation, and computationally efficient embedding