Quantum-mechanical sum rules and gauge invariance: A study of the HF molecule