Generalized path-integral formalism of the polaron problem and its second-order semi-invariant correction to the ground-state energy