(expr)
return list_to_tuple_rec(ricci)
Return the components of the Ricci tensor expressed in a given basis.

    Given a metric it calculates the components of the Ricci tensor in the
    canonical basis of the coordinate system in which the metric expression is
    given.

    Examples
    ========

    >>> from sympy import pprint, exp
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import metric_to_Ricci_components, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Ricci_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    ((0, 0), (0, 0))

    >>> non_trivial_metric = exp(2*R2.r)*TP(R2.dr, R2.dr) + \
                             R2.r**2*TP(R2.dtheta, R2.dtheta)
    >>> non_trivial_metric
    exp(2*r)*TensorProduct(dr, dr) + r**2*TensorProduct(dtheta, dtheta)
    >>> metric_to_Ricci_components(non_trivial_metric) #TODO why is this not simpler
    ((r**(-1), 0), (0, -exp(-2*r)*r + 2*r*exp(-2*r)))
Return the components of the Ricci tensor expressed in a given basis.
Return the components of the Ricci tensor expressed in a given basis .
def metric_to_Ricci_components(expr):
    """Return the components of the Ricci tensor expressed in a given basis.

    Given a metric it calculates the components of the Ricci tensor in the
    canonical basis of the coordinate system in which the metric expression is
    given.

    Examples
    ========

    >>> from sympy import pprint, exp
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import metric_to_Ricci_components, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Ricci_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    ((0, 0), (0, 0))

    >>> non_trivial_metric = exp(2*R2.r)*TP(R2.dr, R2.dr) + \
                             R2.r**2*TP(R2.dtheta, R2.dtheta)
    >>> non_trivial_metric
    exp(2*r)*TensorProduct(dr, dr) + r**2*TensorProduct(dtheta, dtheta)
    >>> metric_to_Ricci_components(non_trivial_metric) #TODO why is this not simpler
    ((r**(-1), 0), (0, -exp(-2*r)*r + 2*r*exp(-2*r)))

    """
    riemann = metric_to_Riemann_components(expr)
    coord_sys = expr.atoms(CoordSystem).pop()
    indices = list(range(coord_sys.dim))
    ricci = [[Add(*[riemann[k][i][k][j] for k in indices])
              for j in indices]
             for i in indices]
    return list_to_tuple_rec(ricci)
def metric_to_Ricci_components ( expr ) : riemann = metric_to_Riemann_components ( expr ) coord_sys = expr . atoms ( CoordSystem ) . pop ( ) indices = list ( range ( coord_sys . dim ) ) ricci = [ [ Add ( * [ riemann [ k ] [ i ] [ k ] [ j ] for k in indices ] ) for j in indices ] for i in indices ] return list_to_tuple_rec ( ricci )