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

    Given a metric it calculates the components of the Riemann 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_Riemann_components, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Riemann_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    ((((0, 0), (0, 0)), ((0, 0), (0, 0))), (((0, 0), (0, 0)), ((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)
    >>> riemann = metric_to_Riemann_components(non_trivial_metric)
    >>> riemann[0]
    (((0, 0), (0, 0)), ((0, -exp(-2*r)*r + 2*r*exp(-2*r)),
        (exp(-2*r)*r - 2*r*exp(-2*r), 0)))
    >>> riemann[1]
    (((0, -r**(-1)), (r**(-1), 0)), ((0, 0), (0, 0)))
Return the components of the Riemann tensor expressed in a given basis.
Return the components of the Riemann tensor expressed in a given basis .
def metric_to_Riemann_components(expr):
    """Return the components of the Riemann tensor expressed in a given basis.

    Given a metric it calculates the components of the Riemann 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_Riemann_components, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Riemann_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    ((((0, 0), (0, 0)), ((0, 0), (0, 0))), (((0, 0), (0, 0)), ((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)
    >>> riemann = metric_to_Riemann_components(non_trivial_metric)
    >>> riemann[0]
    (((0, 0), (0, 0)), ((0, -exp(-2*r)*r + 2*r*exp(-2*r)),
        (exp(-2*r)*r - 2*r*exp(-2*r), 0)))
    >>> riemann[1]
    (((0, -r**(-1)), (r**(-1), 0)), ((0, 0), (0, 0)))

    """
    ch_2nd = metric_to_Christoffel_2nd(expr)
    coord_sys = expr.atoms(CoordSystem).pop()
    indices = list(range(coord_sys.dim))
    deriv_ch = [[[[d(ch_2nd[i][j][k])
                   for d in coord_sys.base_vectors()]
                  for k in indices]
                 for j in indices]
                for i in indices]
    riemann_a = [[[[deriv_ch[rho][sig][nu][mu] - deriv_ch[rho][sig][mu][nu]
                    for nu in indices]
                   for mu in indices]
                  for sig in indices]
                     for rho in indices]
    riemann_b = [[[[Add(*[ch_2nd[rho][l][mu]*ch_2nd[l][sig][nu] - ch_2nd[rho][l][nu]*ch_2nd[l][sig][mu] for l in indices])
                    for nu in indices]
                   for mu in indices]
                  for sig in indices]
                 for rho in indices]
    riemann = [[[[riemann_a[rho][sig][mu][nu] + riemann_b[rho][sig][mu][nu]
                  for nu in indices]
                     for mu in indices]
                for sig in indices]
               for rho in indices]
    return list_to_tuple_rec(riemann)
def metric_to_Riemann_components ( expr ) : ch_2nd = metric_to_Christoffel_2nd ( expr ) coord_sys = expr . atoms ( CoordSystem ) . pop ( ) indices = list ( range ( coord_sys . dim ) ) deriv_ch = [ [ [ [ d ( ch_2nd [ i ] [ j ] [ k ] ) for d in coord_sys . base_vectors ( ) ] for k in indices ] for j in indices ] for i in indices ] riemann_a = [ [ [ [ deriv_ch [ rho ] [ sig ] [ nu ] [ mu ] - deriv_ch [ rho ] [ sig ] [ mu ] [ nu ] for nu in indices ] for mu in indices ] for sig in indices ] for rho in indices ] riemann_b = [ [ [ [ Add ( * [ ch_2nd [ rho ] [ l ] [ mu ] * ch_2nd [ l ] [ sig ] [ nu ] - ch_2nd [ rho ] [ l ] [ nu ] * ch_2nd [ l ] [ sig ] [ mu ] for l in indices ] ) for nu in indices ] for mu in indices ] for sig in indices ] for rho in indices ] riemann = [ [ [ [ riemann_a [ rho ] [ sig ] [ mu ] [ nu ] + riemann_b [ rho ] [ sig ] [ mu ] [ nu ] for nu in indices ] for mu in indices ] for sig in indices ] for rho in indices ] return list_to_tuple_rec ( riemann )