Calculation of inertia defect: Part I. General formulation