  We consider a weakly coupled gauge theory where charged particles all have
large gaps (ie no Higgs condensation to break the gauge "symmetry") and the
field strength fluctuates only weakly. We ask what kind of topological terms
can be added to the Lagrangian of such a weakly coupled gauge theory. In this
paper, we systematically construct quantized topological terms which are
generalization of the Chern-Simons terms and $F\wedge F$ terms, in space-time
dimensions $d$ and for any gauge groups (continuous or discrete), using each
element of the topological cohomology classes $H^{d+1}(BG,\Z)$ on the
classifying space $BG$ of the gauge group $G$.
  In 3$d$ or for finite gauge groups above 3$d$, the weakly coupled gauge
theories are gapped. So our results on topological terms can be viewed as a
systematic construction of gapped topologically ordered phases of weakly
coupled gauge theories. In other cases, the weakly coupled gauge theories are
gapless. So our results can be viewed as an attempt to systematically construct
different gapless phases of weakly coupled gauge theories.
  Amazingly, the bosonic symmetry protected topological (SPT) phases with a
finite on-site symmetry group $G$ are also classified by the same
$H^{d+1}(BG,\Z)$. (SPT phases are gapped quantum phases with a symmetry and
trivial topological order.) In this paper, we show an explicit duality relation
between topological gauge theories with the quantized topological terms and the
bosonic SPT phases, for any finite group $G$ and in any dimensions; a result
first obtained by Levin and Gu. We also study the relation between topological
lattice gauge theory and the string-net states with non-trivial topological
order and no symmetry.
