We lay down the ab initio many-body quantum theory of electrons and phonons
in equilibrium as well as in steady-state or time-varying settings. The focus is on the
harmonic approximation, but the developed tools can readily incorporate anharmonic effects.
We begin by showing the necessity of determining the ab initio Hamiltonian in a
self-consistent manner to ensure the existence of an equilibrium state. We then identify
the correct partitioning into a “noninteracting” and an “interacting” part to carry out
diagrammatic expansions in terms of dressed propagators and screened interactions. The final
outcome is the finite-temperature nonequilibrium extension of the Hedin equations, showcasing
the emergence of the coupling between electrons and coherent phonons through the time-local
Ehrenfest diagram. The Hedin equations have limited practical utility for real-time simulations
of systems driven out of equilibrium by external fields. We then derive the Kadanoff-Baym equations
for electrons and phonons, discuss the theory of conserving approximations and show how to
recover the Born-Oppenheimer approximation. We conclude by pointing out a possible
correlation-induced splitting of the phonon dispersion in materials with no time-reversal
invariance.