Formalism for the T(d, n)4He and 3He(d, p)4He reactions