(expr)
return non_scalars[0], symmetries
Determine outer indices of an Add object.

    In a sum, each term must have the same set of outer indices.  A valid
    expression could be

        x(i)*y(j) - x(j)*y(i)

    But we do not allow expressions like:

        x(i)*y(j) - z(j)*z(j)

    FIXME: Add support for Numpy broadcasting

    >>> from sympy.tensor.index_methods import _get_indices_Add
    >>> from sympy.tensor.indexed import IndexedBase, Idx
    >>> i, j, k = map(Idx, ['i', 'j', 'k'])
    >>> x = IndexedBase('x')
    >>> y = IndexedBase('y')
    >>> _get_indices_Add(x[i] + x[k]*y[i, k])
    (set([i]), {})
Determine outer indices of an Add object.
Determine outer indices of an Add object .
def _get_indices_Add(expr):
    """Determine outer indices of an Add object.

    In a sum, each term must have the same set of outer indices.  A valid
    expression could be

        x(i)*y(j) - x(j)*y(i)

    But we do not allow expressions like:

        x(i)*y(j) - z(j)*z(j)

    FIXME: Add support for Numpy broadcasting

    >>> from sympy.tensor.index_methods import _get_indices_Add
    >>> from sympy.tensor.indexed import IndexedBase, Idx
    >>> i, j, k = map(Idx, ['i', 'j', 'k'])
    >>> x = IndexedBase('x')
    >>> y = IndexedBase('y')
    >>> _get_indices_Add(x[i] + x[k]*y[i, k])
    (set([i]), {})

    """

    inds = list(map(get_indices, expr.args))
    inds, syms = list(zip(*inds))

    # allow broadcast of scalars
    non_scalars = [x for x in inds if x != set()]
    if not non_scalars:
        return set(), {}

    if not all([x == non_scalars[0] for x in non_scalars[1:]]):
        raise IndexConformanceException("Indices are not consistent: %s" % expr)
    if not reduce(lambda x, y: x != y or y, syms):
        symmetries = syms[0]
    else:
        # FIXME: search for symmetries
        symmetries = {}

    return non_scalars[0], symmetries
def _get_indices_Add ( expr ) : inds = list ( map ( get_indices , expr . args ) ) inds , syms = list ( zip ( * inds ) ) # allow broadcast of scalars non_scalars = [ x for x in inds if x != set ( ) ] if not non_scalars : return set ( ) , { } if not all ( [ x == non_scalars [ 0 ] for x in non_scalars [ 1 : ] ] ) : raise IndexConformanceException ( "Indices are not consistent: %s" % expr ) if not reduce ( lambda x , y : x != y or y , syms ) : symmetries = syms [ 0 ] else : # FIXME: search for symmetries symmetries = { } return non_scalars [ 0 ] , symmetries