  We prove duality relations for two interacting particle systems: the
$q$-deformed totally asymmetric simple exclusion process ($q$-TASEP) and the
asymmetric simple exclusion process (ASEP). Expectations of the duality
functionals correspond to certain joint moments of particle locations or
integrated currents, respectively. Duality implies that they solve systems of
ODEs. These systems are integrable and for particular step and half-stationary
initial data we use a nested contour integral ansatz to provide explicit
formulas for the systems' solutions, and hence also the moments. We form
Laplace transform-like generating functions of these moments and via residue
calculus we compute two different types of Fredholm determinant formulas for
such generating functions. For ASEP, the first type of formula is new and
readily lends itself to asymptotic analysis (as necessary to reprove GUE
Tracy--Widom distribution fluctuations for ASEP), while the second type of
formula is recognizable as closely related to Tracy and Widom's ASEP formula
[Comm. Math. Phys. 279 (2008) 815--844, J. Stat. Phys. 132 (2008) 291--300,
Comm. Math. Phys. 290 (2009) 129--154, J. Stat. Phys. 140 (2010) 619--634]. For
$q$-TASEP, both formulas coincide with those computed via Borodin and Corwin's
Macdonald processes [Probab. Theory Related Fields (2014) 158 225--400]. Both
$q$-TASEP and ASEP have limit transitions to the free energy of the continuum
directed polymer, the logarithm of the solution of the stochastic heat equation
or the Hopf--Cole solution to the Kardar--Parisi--Zhang equation. Thus,
$q$-TASEP and ASEP are integrable discretizations of these continuum objects;
the systems of ODEs associated to their dualities are deformed discrete quantum
delta Bose gases; and the procedure through which we pass from expectations of
their duality functionals to characterizing generating functions is a rigorous
version of the replica trick in physics.
