  We improve upper bounds on sphere packing densities and sizes of spherical
codes in high dimensions. In particular, we prove that the maximal sphere
packing densities $\delta_n$ in $\mathbb{R}^n$ satisfy \[\delta_n\leq
\frac{1+o(1)}{e}\cdot \delta^{\text{KL}}_{n}\] for large $n$, where
$\delta^{\text{KL}}_{n}$ is the best bound on $\delta_n$ obtained essentially
by Kabatyanskii and Levenshtein from the 1970s with improvements over the
years. We also obtain the same improvement factor for the maximal size
$M(n,\theta)$ of $\theta$-spherical codes in $S^{n-1}$: for angles
$0<\theta<\theta'\leq\frac{\pi}{2}$, \[M(n,\theta)\leq \frac{1+o(1)}{e}\cdot
\frac{M_{\text{Lev}}(n-1,\theta')}{\mu_n(\theta,\theta')}\] for large $n$,
where $\mu_n(\theta,\theta')$ is the mass of the spherical cap in the unit
sphere $S^{n-1}$ of radius $\frac{\sin(\theta/2)}{\sin(\theta'/2)}$, and
$M_{\text{Lev}}(n-1,\theta')$ is Levenshtein's upper bound on $M(n-1,\theta')$
when applying the Delsarte linear programming method to Levenshtein's optimal
polynomials. In fact, we prove that there are no analytic losses in our
arguments and that the constant $\frac{1}{e}=0.367...$ is optimal for the class
of functions considered. Our results also show that the improvement factor does
not depend on the special angle $\theta^*=62.997...^{\circ}$, explaining the
numerics in arXiv:2001.00185. In the spherical codes case, the above inequality
improves the Kabatyanskii--Levenshtein bound by a factor of $0.2304...$ on
geometric average. Along the way, we construct a general class of functions
using Stiefel manifolds for which we prove general results and study the
improvement factors obtained from them in various settings.and study the
improvement factors obtained from them in various settings.
