Analytic approach for optimal quantization of diffractive optical elements