  We compute the partition function of four-dimensional abelian gauge theory on
a general four-torus T4 with flat metric using Dirac quantization. In addition
to an SL(4, Z) symmetry, it possesses SL(2,Z) symmetry that is electromagnetic
S-duality. We show explicitly how this SL(2, Z) S-duality of the 4d abelian
gauge theory has its origin in symmetries of the 6d (2,0) tensor theory, by
computing the partition function of a single fivebrane compactified on T2 x T4,
which has SL(2,Z) x SL(4,Z) symmetry. If we identify the couplings of the
abelian gauge theory \tau = {\theta\over 2\pi} + i{4\pi\over e^2} with the
complex modulus of the T2 torus, \tau = \beta^2 + i {R_1\over R_2}, then in the
small T2 limit, the partition function of the fivebrane tensor field can be
factorized, and contains the partition function of the 4d gauge theory. In this
way the SL(2,Z) symmetry of the 6d tensor partition function is identified with
the S-duality symmetry of the 4d gauge partition function. Each partition
function is the product of zero mode and oscillator contributions, where the
SL(2,Z) acts suitably. For the 4d gauge theory, which has a Lagrangian, this
product redistributes when using path integral quantization.
