First-principles calculation of higher-order elastic constants using exact deformation-gradient tensors