(expr, _strict=False)
Return the covariant order of an expression.

    Examples
    ========

    >>> from sympy.diffgeom import covariant_order
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.abc import a
    >>> covariant_order(a)
    0
    >>> covariant_order(a*R2.x + 2)
    0
    >>> covariant_order(a*R2.x*R2.dy + R2.dx)
    1
Return the covariant order of an expression.
Return the covariant order of an expression .
def covariant_order(expr, _strict=False):
    """Return the covariant order of an expression.

    Examples
    ========

    >>> from sympy.diffgeom import covariant_order
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.abc import a
    >>> covariant_order(a)
    0
    >>> covariant_order(a*R2.x + 2)
    0
    >>> covariant_order(a*R2.x*R2.dy + R2.dx)
    1

    """
    # TODO move some of this to class methods.
    # TODO rewrite using the .as_blah_blah methods
    if isinstance(expr, Add):
        orders = [covariant_order(e) for e in expr.args]
        if len(set(orders)) != 1:
            raise ValueError('Misformed expression containing form fields of varying order.')
        return orders[0]
    elif isinstance(expr, Mul):
        orders = [covariant_order(e) for e in expr.args]
        not_zero = [o for o in orders if o != 0]
        if len(not_zero) > 1:
            raise ValueError('Misformed expression containing multiplication between forms.')
        return 0 if not not_zero else not_zero[0]
    elif isinstance(expr, Pow):
        if covariant_order(expr.base) or covariant_order(expr.exp):
            raise ValueError(
                'Misformed expression containing a power of a form.')
        return 0
    elif isinstance(expr, Differential):
        return covariant_order(*expr.args) + 1
    elif isinstance(expr, TensorProduct):
        return sum(covariant_order(a) for a in expr.args)
    elif not _strict or expr.atoms(BaseScalarField):
        return 0
    else:  # If it does not contain anything related to the diffgeom module and it is _strict
        return -1
def covariant_order ( expr , _strict = False ) : # TODO move some of this to class methods. # TODO rewrite using the .as_blah_blah methods if isinstance ( expr , Add ) : orders = [ covariant_order ( e ) for e in expr . args ] if len ( set ( orders ) ) != 1 : raise ValueError ( 'Misformed expression containing form fields of varying order.' ) return orders [ 0 ] elif isinstance ( expr , Mul ) : orders = [ covariant_order ( e ) for e in expr . args ] not_zero = [ o for o in orders if o != 0 ] if len ( not_zero ) > 1 : raise ValueError ( 'Misformed expression containing multiplication between forms.' ) return 0 if not not_zero else not_zero [ 0 ] elif isinstance ( expr , Pow ) : if covariant_order ( expr . base ) or covariant_order ( expr . exp ) : raise ValueError ( 'Misformed expression containing a power of a form.' ) return 0 elif isinstance ( expr , Differential ) : return covariant_order ( * expr . args ) + 1 elif isinstance ( expr , TensorProduct ) : return sum ( covariant_order ( a ) for a in expr . args ) elif not _strict or expr . atoms ( BaseScalarField ) : return 0 else : # If it does not contain anything related to the diffgeom module and it is _strict return - 1