# Path: drudge/utils.py
# def sympy_key(expr):
#     """Get the key for ordering SymPy expressions.
# 
#     This function assumes that the given expression is already sympified.
#     """
# 
#     return count_ops(expr), default_sort_key(expr)


import itertools
import typing
import warnings
from sympy import conjugate, Symbol
from .canonpy import canon_eldag, Group, Perm
from .utils import sympy_key
    from .term import Vec

    """

    eldag = Eldag()
    factor_idxes = []

    # Simple treatment of edges among sums: a sum has an edge to another sum if
    # and only if the dummy of the other sum appears in its bounds.
    #
    # In this way, for most problem with no relation among the summations,
    # basically no overhead is introduced.  And it is generally sufficient for
    # simple relationships among the summations.
    #
    # TODO: Better treatment of dummies in summation bounds.

    idx_of_dummies = {v[0]: i for i, v in enumerate(sums)}

    # No need to touch edges for sums.
    for _, i in sums:
        edges = []
        free_var_keys = []  # As part of the colour.
        with_dummy = 0
        if i.bounded:
            bounded = 1
            symbs = i.lower.atoms(Symbol) | i.upper.atoms(Symbol)
            for j in symbs:
                if j in idx_of_dummies:
                    with_dummy = 1
                    edges.append(idx_of_dummies[j])
                else:

# Path: drudge/utils.py
# def sympy_key(expr):
#     """Get the key for ordering SymPy expressions.
# 
#     This function assumes that the given expression is already sympified.
#     """
# 
#     return count_ops(expr), default_sort_key(expr)


# Path: drudge/canon.py
import itertools
import typing
import warnings
from sympy import conjugate, Symbol
from .canonpy import canon_eldag, Group, Perm
from .utils import sympy_key
    from .term import Vec


    """

    eldag = Eldag()
    factor_idxes = []

    # Simple treatment of edges among sums: a sum has an edge to another sum if
    # and only if the dummy of the other sum appears in its bounds.
    #
    # In this way, for most problem with no relation among the summations,
    # basically no overhead is introduced.  And it is generally sufficient for
    # simple relationships among the summations.
    #
    # TODO: Better treatment of dummies in summation bounds.

    idx_of_dummies = {v[0]: i for i, v in enumerate(sums)}

    # No need to touch edges for sums.
    for _, i in sums:
        edges = []
        free_var_keys = []  # As part of the colour.
        with_dummy = 0
        if i.bounded:
            bounded = 1
            symbs = i.lower.atoms(Symbol) | i.upper.atoms(Symbol)
            for j in symbs:
                if j in idx_of_dummies:
                    with_dummy = 1
                    edges.append(idx_of_dummies[j])
                else:

                    free_var_keys.append(sympy_key(j))