Optimization of trigonometric polynomials with crystallographic symmetry and spectral bounds for set avoiding graphs