human
Complete the below
def _get_ordered_dummies(mul, verbose=False):

    ''''Returns all dummies in the mul sorted in canonical order
    The purpose of the canonical ordering is that dummies can be substituted
    consistently across terms with the result that equivalent terms can be
    simplified.
    It is not possible to determine if two terms are equivalent based solely on
    the dummy order.  However, a consistent substitution guided by the ordered
    dummies should lead to trivially (non-)equivalent terms, thereby revealing
    the equivalence.  This also means that if two terms have identical sequences of
    dummies, the (non-)equivalence should already be apparent.
    Strategy
    The canoncial order is given by an arbitrary sorting rule.  A sort key
    is determined for each dummy as a tuple that depends on all factors where
    the index is present.  The dummies are thereby sorted according to the
    contraction structure of the term, instead of sorting based solely on the
    dummy symbol itself.
    After all dummies in the term has been assigned a key, we check for identical
    keys, i.e. unorderable dummies.  If any are found, we call a specialized
    method, _determine_ambiguous(), that will determine a unique order based
    on recursive calls to _get_ordered_dummies().
    Key description
    A high level description of the sort key:
    1. Range of the dummy index
    2. Relation to external (non-dummy) indices
    3. Position of the index in the first factor
    4. Position of the index in the second factor
    The sort key is a tuple with the following components:
    1. A single character indicating the range of the dummy (above, below
    or general.)
    2. A list of strings with fully masked string representations of all
    factors where the dummy is present.  By masked, we mean that dummies
    are represented by a symbol to indicate either below fermi, above or
    general.  No other information is displayed about the dummies at
    this point.  The list is sorted stringwise.
    3. An integer number indicating the position of the index, in the...'''
assistant
#Here is Python code to determine if two terms are equivalent based solely on
.
    args = Mul.make_args(mul)
    fac_dum = dict([(fac, fac.atoms(Dummy)) for fac in args])
    fac_repr = dict([(fac, __kprint(fac)) for fac in args])
    all_dums = set().union(*fac_dum.values())
    mask = {}
    for d in all_dums:
        if d.assumptions0.get('below_fermi'):
            mask[d] = '0'
        elif d.assumptions0.get('above_fermi'):
            mask[d] = '1'
        else:
            mask[d] = '2'
    dum_repr = {d: __kprint(d) for d in all_dums}
    def _key(d):
        dumstruct = [fac for fac in fac_dum if (d in fac_dum[fac])]
        other_dums = set().union(*[fac_dum[fac] for fac in dumstruct])
        fac = dumstruct[(-1)]
        if (other_dums is fac_dum[fac]):
            other_dums = fac_dum[fac].copy()
        other_dums.remove(d)
        masked_facs = [fac_repr[fac] for fac in dumstruct]
        for d2 in other_dums:
            masked_facs = [fac.replace(dum_repr[d2], mask[d2]) for fac in masked_facs]
        all_masked = [fac.replace(dum_repr[d], mask[d]) for fac in masked_facs]
        masked_facs = dict(list(zip(dumstruct, masked_facs)))
        if has_dups(all_masked):
            all_masked.sort()
            return (mask[d], tuple(all_masked))
        keydict = dict(list(zip(dumstruct, all_masked)))
        dumstruct.sort(key=(lambda x: keydict[x]))
        all_masked.sort()
        pos_val = []
        for fac in dumstruct:
            if isinstance(fac, AntiSymmetricTensor):
                if (d in fac.upper):
                    pos_val.append('u')
                if (d in fac.lower):
                    pos_val.append('l')
            elif isinstance(fac, Creator):
                pos_val.append('u')
            elif isinstance(fac, Annihilator):
                pos_val.append('l')
            elif isinstance(fac, NO):
                ops = [op for op in fac if op.has(d)]
                for op in ops:
                    if isinstance(op, Creator):
                        pos_val.append('u')
                    else:
                        pos_val.append('l')
    ...