Deriving equations of motion from an action has several advantages. First, it allows for easy unification of general relativity with other classical field theories, which are also formulated in terms of an action. In the process, the derivation identifies a natural candidate for the source term coupling the metric to matter fields. Moreover, symmetries of the action allow for easy identification of conserved quantities through Noether's theorem. In general relativity, the action is usually assumed to be a functional of the metric, and the connection is given by the Levi-Civita connection. The Palatini formulation of general relativity assumes the metric and connection to be independent, and varies with respect to both independently, which makes it possible to include fermionic matter fields with non-integer spin. The Einstein equations in the presence of matter are given by adding the matter action to the Einstein-Hilbert action.
Suppose that the full action of the theory is given by the Einstein–Hilbert term plus a term describing any matter fields appearing in the theory. The action principle then tells us that to recover a physical law, we must demand that the variation of this action with respect to the inverse metric be zero, yielding Since this equation should hold for any variation, it implies that is the equation of motion for the metric field. The right hand side of this equation is proportional to the stress-energy tensor, To calculate the left hand side of the equation we need the variations of the Ricci scalar and the determinant of the metric. These can be obtained by standard textbook calculations such as the one given below, which is strongly based on the one given in.
Variation of the Riemann tensor, the Ricci tensor, and the Ricci scalar
To calculate the variation of the Ricci scalar we calculate first the variation of the Riemann curvature tensor, and then the variation of the Ricci tensor. So, the Riemann curvature tensor is defined as Since the Riemann curvature depends only on the Levi-Civita connection, the variation of the Riemann tensor can be calculated as Now, since is the difference of two connections, it is a tensor and we can thus calculate its covariant derivative, We can now observe that the expression for the variation of Riemann curvature tensor above is equal to the difference of two such terms, We may now obtain the variation of the Ricci curvature tensor simply by contracting two indices of the variation of the Riemann tensor, and get the Palatini identity: The Ricci scalar is defined as Therefore, its variation with respect to the inverse metric is given by In the second line we used the metric compatibility of the covariant derivative,, and the previously obtained result for the variation of the Ricci curvature. The last term, multiplied by, becomes a total derivative, since for any vector and any tensor density we have: and thus by Stokes' theorem only yields a boundary term when integrated. The boundary term is in general non-zero, because the integrand depends not only on but also on its partial derivatives ; see the article Gibbons–Hawking–York boundary term for details. However when the variation of the metric vanishes in a neighbourhood of the boundary or when there is no boundary, this term does not contribute to the variation of the action. And we thus obtain at events not in the closure of the boundary.
Variation of the determinant
, the rule for differentiating a determinant, gives: or one could transform to a coordinate system where is diagonal and then apply the product rule to differentiate the product of factors on the main diagonal. Using this we get In the last equality we used the fact that which follows from the rule for differentiating the inverse of a matrix Thus we conclude that
Equation of motion
Now that we have all the necessary variations at our disposal, we can insert and into the equation of motion for the metric field to obtain which is the Einstein field equations, and has been chosen such that the non-relativistic limit yields the usual form of Newton's gravity law, where is the gravitational constant.
Cosmological constant
When a cosmological constant Λ is included in the Lagrangian, the action: Taking variations with respect to the inverse metric: Using the action principle: Combining this expression with the results obtained before: We can obtain: With, the expression becomes the field equations with a cosmological constant: