Theory and algorithmic applications of the proximal mapping and Moreau envelope