Compact representation of generalized molecular polarizabilities and efficient calculation of polarization energy in an arbitrary electric field