Two-level system coupled to phonons: Full analytical solution