(seq, directed=True, is_set=False, small=None)
return tuple(best)
Return a tuple where the smallest element appears first; if
    ``directed`` is True (default) then the order is preserved, otherwise
    the sequence will be reversed if that gives a smaller ordering.

    If every element appears only once then is_set can be set to True
    for more efficient processing.

    If the smallest element is known at the time of calling, it can be
    passed and the calculation of the smallest element will be omitted.

    Examples
    ========

    >>> from sympy.combinatorics.polyhedron import minlex
    >>> minlex((1, 2, 0))
    (0, 1, 2)
    >>> minlex((1, 0, 2))
    (0, 2, 1)
    >>> minlex((1, 0, 2), directed=False)
    (0, 1, 2)

    >>> minlex('11010011000', directed=True)
    '00011010011'
    >>> minlex('11010011000', directed=False)
    '00011001011'
Return a tuple where the smallest element appears first; if
    ``directed`` is True (default) then the order is preserved, otherwise
    the sequence will be reversed if that gives a smaller ordering.
Return a tuple where the smallest element appears first ; if directed is True ( default ) then the order is preserved otherwise the sequence will be reversed if that gives a smaller ordering .
def minlex(seq, directed=True, is_set=False, small=None):
    """
    Return a tuple where the smallest element appears first; if
    ``directed`` is True (default) then the order is preserved, otherwise
    the sequence will be reversed if that gives a smaller ordering.

    If every element appears only once then is_set can be set to True
    for more efficient processing.

    If the smallest element is known at the time of calling, it can be
    passed and the calculation of the smallest element will be omitted.

    Examples
    ========

    >>> from sympy.combinatorics.polyhedron import minlex
    >>> minlex((1, 2, 0))
    (0, 1, 2)
    >>> minlex((1, 0, 2))
    (0, 2, 1)
    >>> minlex((1, 0, 2), directed=False)
    (0, 1, 2)

    >>> minlex('11010011000', directed=True)
    '00011010011'
    >>> minlex('11010011000', directed=False)
    '00011001011'

    """
    is_str = isinstance(seq, str)
    seq = list(seq)
    if small is None:
        small = min(seq, key=default_sort_key)
    if is_set:
        i = seq.index(small)
        if not directed:
            n = len(seq)
            p = (i + 1) % n
            m = (i - 1) % n
            if default_sort_key(seq[p]) > default_sort_key(seq[m]):
                seq = list(reversed(seq))
                i = n - i - 1
        if i:
            seq = rotate_left(seq, i)
        best = seq
    else:
        count = seq.count(small)
        if count == 1 and directed:
            best = rotate_left(seq, seq.index(small))
        else:
            # if not directed, and not a set, we can't just
            # pass this off to minlex with is_set True since
            # peeking at the neighbor may not be sufficient to
            # make the decision so we continue...
            best = seq
            for i in range(count):
                seq = rotate_left(seq, seq.index(small, count != 1))
                if seq < best:
                    best = seq
                # it's cheaper to rotate now rather than search
                # again for these in reversed order so we test
                # the reverse now
                if not directed:
                    seq = rotate_left(seq, 1)
                    seq = list(reversed(seq))
                    if seq < best:
                        best = seq
                    seq = list(reversed(seq))
                    seq = rotate_right(seq, 1)
    # common return
    if is_str:
        return ''.join(best)
    return tuple(best)
def minlex ( seq , directed = True , is_set = False , small = None ) : is_str = isinstance ( seq , str ) seq = list ( seq ) if small is None : small = min ( seq , key = default_sort_key ) if is_set : i = seq . index ( small ) if not directed : n = len ( seq ) p = ( i + 1 ) % n m = ( i - 1 ) % n if default_sort_key ( seq [ p ] ) > default_sort_key ( seq [ m ] ) : seq = list ( reversed ( seq ) ) i = n - i - 1 if i : seq = rotate_left ( seq , i ) best = seq else : count = seq . count ( small ) if count == 1 and directed : best = rotate_left ( seq , seq . index ( small ) ) else : # if not directed, and not a set, we can't just # pass this off to minlex with is_set True since # peeking at the neighbor may not be sufficient to # make the decision so we continue... best = seq for i in range ( count ) : seq = rotate_left ( seq , seq . index ( small , count != 1 ) ) if seq < best : best = seq # it's cheaper to rotate now rather than search # again for these in reversed order so we test # the reverse now if not directed : seq = rotate_left ( seq , 1 ) seq = list ( reversed ( seq ) ) if seq < best : best = seq seq = list ( reversed ( seq ) ) seq = rotate_right ( seq , 1 ) # common return if is_str : return '' . join ( best ) return tuple ( best )