Analytical dynamics of discrete systems