<commit_before>from .permutations import Permutation
from .util import _distribute_gens_by_base


rmul = Permutation.rmul


def _cmp_perm_lists(first, second):
    """
    Compare two lists of permutations as sets.

    This is used for testing purposes. Since the array form of a
    permutation is currently a list, Permutation is not hashable
    and cannot be put into a set.

    Examples
    ========

    >>> a = Permutation([0, 2, 3, 4, 1])
    >>> b = Permutation([1, 2, 0, 4, 3])
    >>> c = Permutation([3, 4, 0, 1, 2])
    >>> ls1 = [a, b, c]
    >>> ls2 = [b, c, a]
    >>> _cmp_perm_lists(ls1, ls2)
    True

    """
    return {tuple(a) for a in first} == \
        {tuple(a) for a in second}


def _naive_list_centralizer(self, other, af=False):
    """
    Return a list of elements for the centralizer of a subgroup/set/element.

    This is a brute force implementation that goes over all elements of the
    group and checks for membership in the centralizer. It is used to
    test ``.centralizer()`` from ``diofant.combinatorics.perm_groups``.

    Examples
    ========

    >>> D = DihedralGroup(4)
    >>> _naive_list_centralizer(D, D)
    [Permutation([0, 1, 2, 3]), Permutation([2, 3, 0, 1])]

    See Also
    ========

    diofant.combinatorics.perm_groups.PermutationGroup.centralizer

    """
    from .perm_groups import PermutationGroup
    from .permutations import _af_commutes_with
    if hasattr(other, 'generators'):
        elements = list(self.generate_dimino(af=True))
        gens = [x._array_form for x in other.generators]

        def commutes_with_gens(x):
            return all(_af_commutes_with(x, gen) for gen in gens)

        centralizer_list = []
        if not af:
            for element in elements:
                if commutes_with_gens(element):
                    centralizer_list.append(Permutation._af_new(element))
        else:<commit_msg>combinatorics: alter doctest<commit_after>from .permutations import Permutation
from .util import _distribute_gens_by_base


rmul = Permutation.rmul


def _cmp_perm_lists(first, second):
    """
    Compare two lists of permutations as sets.

    This is used for testing purposes. Since the array form of a
    permutation is currently a list, Permutation is not hashable
    and cannot be put into a set.

    Examples
    ========

    >>> a = Permutation([0, 2, 3, 4, 1])
    >>> b = Permutation([1, 2, 0, 4, 3])
    >>> c = Permutation([3, 4, 0, 1, 2])
    >>> ls1 = [a, b, c]
    >>> ls2 = [b, c, a]
    >>> _cmp_perm_lists(ls1, ls2)
    True

    """
    return {tuple(a) for a in first} == \
        {tuple(a) for a in second}


def _naive_list_centralizer(self, other, af=False):
    """
    Return a list of elements for the centralizer of a subgroup/set/element.

    This is a brute force implementation that goes over all elements of the
    group and checks for membership in the centralizer. It is used to
    test ``.centralizer()`` from ``diofant.combinatorics.perm_groups``.

    Examples
    ========

    >>> D = DihedralGroup(4)
    >>> _naive_list_centralizer(D, D)
    [Permutation(3), Permutation(0, 2)(1, 3)]

    See Also
    ========

    diofant.combinatorics.perm_groups.PermutationGroup.centralizer

    """
    from .perm_groups import PermutationGroup
    from .permutations import _af_commutes_with
    if hasattr(other, 'generators'):
        elements = list(self.generate_dimino(af=True))
        gens = [x._array_form for x in other.generators]

        def commutes_with_gens(x):
            return all(_af_commutes_with(x, gen) for gen in gens)

        centralizer_list = []
        if not af:
            for element in elements:
                if commutes_with_gens(element):
                    centralizer_list.append(Permutation._af_new(element))
        else:
{'fraction_non_alphanumeric': 0.11423319327731092, 'fraction_numerical': 0.013918067226890757, 'mean_word_length': 2.752709359605911, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '951712', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1181, 'n_words': 377}