Canonical factorization of continuous functions on the d-torus