Repository: sympy/sympy
File: sympy/combinatorics/perm_groups.py (Python)

Code before:
        As described in the documentation for the .conjugacy_class() function,
        conjugacy is an equivalence relation on a group G which partitions the
        set of elements. This method returns a list of all these conjugacy
        classes of G.

        Examples
        ========

        >>> from sympy.combinatorics import SymmetricGroup
        >>> SymmetricGroup(3).conjugacy_classes()
        [{(2)}, {(0 1 2), (0 2 1)}, {(0 2), (1 2), (2)(0 1)}]

        """
        identity = _af_new(list(range(self.degree)))
        known_elements = {identity}
        classes = [known_elements.copy()]

        for x in self.generate():
            if x not in known_elements:
                new_class = self.conjugacy_class(x)
                classes.append(new_class)
                known_elements.update(new_class)

        return classes

    def molien_series(self, x: Basic | None = None) -> FormalPowerSeries:
        r"""Return the Molien series for the permutation action on
        ``k[x_1, ..., x_n]``.

        Explanation
        ===========

        For a finite permutation group `G \le S_n`, this computes the Molien
        series

        .. math::
            \mathrm{Mol}_G(t) = \frac{1}{|G|}\sum_{g\in G}
            \prod_{i=1}^{n} (1 - t^i)^{-c_i(g)},

        where `c_i(g)` is the number of `i`-cycles of `g`.

        The implementation aggregates by conjugacy classes of ``G``.

        Parameters
        ==========

        x : Symbol, optional
            Indeterminate for the formal power series. Defaults to ``t``.

        Returns
        =======

Review comment (suggestion):
This should probably be Expr rather than Basic. I don't think that this function would work for non-Expr.

Code after:
        conjugacy is an equivalence relation on a group G which partitions the
        set of elements. This method returns a list of all these conjugacy
        classes of G.

        Examples
        ========

        >>> from sympy.combinatorics import SymmetricGroup
        >>> SymmetricGroup(3).conjugacy_classes()
        [{(2)}, {(0 1 2), (0 2 1)}, {(0 2), (1 2), (2)(0 1)}]

        """
        identity = _af_new(list(range(self.degree)))
        known_elements = {identity}
        classes = [known_elements.copy()]

        for x in self.generate():
            if x not in known_elements:
                new_class = self.conjugacy_class(x)
                classes.append(new_class)
                known_elements.update(new_class)

        return classes

    def molien(self, x: Expr | None = None) -> Expr:
        r"""Return the Molien rational function for the permutation action on
        ``k[x_1, ..., x_n]``.

        Explanation
        ===========

        For a finite permutation group `G \le S_n`, this computes the generating function
        for the Molien series

        .. math::
            \mathrm{Mol}_G(t) = \frac{1}{|G|}\sum_{g\in G}
            \prod_{i=1}^{n} (1 - t^i)^{-c_i(g)},

        where `c_i(g)` is the number of `i`-cycles of `g`.

        The implementation aggregates by conjugacy classes of ``G``.

        Parameters
        ==========

        x : Symbol, optional
            Indeterminate for the Molien function. Defaults to ``t``.

        Returns
        =======