  Topological insulators are exotic material that possess conducting surface
states protected by the topology of the system. They can be classified in terms
of their properties under discrete symmetries and are characterized by
topological invariants. The latter has been measured experimentally for several
models in one, two and three dimensions in both condensed matter and quantum
simulation platforms. The recent progress in quantum simulation opens the road
to the simulation of higher dimensional Hamiltonians and in particular of the
4D quantum Hall effect. These systems are characterized by the second Chern
number, a topological invariant that appears in the quantization of the
transverse conductivity for the non-linear response to both external magnetic
and electric fields. This quantity cannot always be computed analytically and
there is therefore a need of an algorithm to compute it numerically. In this
work, we propose an efficient algorithm to compute the second Chern number in
4D systems. We construct the algorithm with the help of lattice gauge theory
and discuss the convergence to the continuous gauge theory. We benchmark the
algorithm on several relevant models, including the 4D Dirac Hamiltonian and
the 4D quantum Hall effect and verify numerically its rapid convergence.
