Repository: sympy/sympy
File: sympy/polys/polyclasses.py (Python)

Code before:
        return coeff, f.per(F)

    def _integrate(f, m: int, j: int) -> Self:
        """Computes the ``m``-th order indefinite integral of ``f`` in ``x_j``. """
        # XXX: This should only be for some domains (can fail over ZZ)
        return f.per(dmp_integrate_in(f._rep, m, j, f.lev, f.dom)) # type: ignore

    def _diff(f, m: int, j: int) -> Self:
        """Computes the ``m``-th order derivative of ``f`` in ``x_j``. """
        return f.per(dmp_diff_in(f._rep, m, j, f.lev, f.dom))

    def _eval(f, a: Any, /) -> Any:
        return dmp_eval_in(f._rep, f.dom.convert(a), 0, f.lev, f.dom)

    def _eval_lev(f, a: Any, j: int, /) -> Any:
        rep = dmp_eval_in(f._rep, f.dom.convert(a), j, f.lev, f.dom)
        return f.new(rep, f.dom, f.lev - 1)

    def _half_gcdex(f, g: Self) -> tuple[Self, Self]:
        """Half extended Euclidean algorithm, if univariate. """
        s, h = dup_half_gcdex(f._rep, g._rep, f.dom) # type: ignore
        return f.per(s), f.per(h)

    def _gcdex(f, g: Self) -> tuple[Self, Self, Self]:
        """Extended Euclidean algorithm, if univariate. """
        s, t, h = dup_gcdex(f._rep, g._rep, cast(Field[Any], f.dom))
        return f.per(s), f.per(t), f.per(h)

    def _invert(f, g: Self) -> Self:
        """Invert ``f`` modulo ``g``, if possible. """
        s = dup_invert(f._rep, g._rep,cast(Field[Any], f.dom))
        return f.per(s)

    def _revert(f, n: int) -> Self:
        """Compute ``f**(-1)`` mod ``x**n``. """
        return f.per(_dmp(dup_revert(f._rep, n, f.dom)))

    def _subresultants(f, g: Self) -> list[Self]:
        """Computes subresultant PRS sequence of ``f`` and ``g``. """
        R = dmp_subresultants(f._rep, g._rep, f.lev, f.dom)
        return list(map(f.per, R))

    def _resultant_includePRS(f, g: Self) -> tuple[DMP[Er] | Er, list[DMP[Er]]]:
        """Computes resultant of ``f`` and ``g`` via PRS. """
        res, R = dmp_resultant(f._rep, g._rep, f.lev, f.dom, includePRS=True)
        # XXX: resultant returns a domain element at level 0...
        if f.lev:
            res = f.new(res, f.dom, f.lev - 1) # type: ignore
        return res, list(map(f.per, R)) # type: ignore

    def _resultant(f, g: Self) -> DMP[Er] | Er:

Review comment (suggestion):
When using `cast` it should always be a stringised annotation.

Code after:
        return coeff, f.per(F)

    def _integrate(f, m: int, j: int) -> Self:
        """Computes the ``m``-th order indefinite integral of ``f`` in ``x_j``. """
        # XXX: This should only be for some domains (can fail over ZZ)
        return f.per(dmp_integrate_in(f._rep, m, j, f.lev, f.dom)) # type: ignore

    def _diff(f, m: int, j: int) -> Self:
        """Computes the ``m``-th order derivative of ``f`` in ``x_j``. """
        return f.per(dmp_diff_in(f._rep, m, j, f.lev, f.dom))

    def _eval(f, a: Any, /) -> Any:
        return dmp_eval_in(f._rep, f.dom.convert(a), 0, f.lev, f.dom)

    def _eval_lev(f, a: Any, j: int, /) -> Any:
        rep = dmp_eval_in(f._rep, f.dom.convert(a), j, f.lev, f.dom)
        return f.new(rep, f.dom, f.lev - 1)

    def _half_gcdex(f, g: Self) -> tuple[Self, Self]:
        """Half extended Euclidean algorithm, if univariate. """
        s, h = dup_half_gcdex(f._rep, g._rep, f.dom) # type: ignore
        return f.per(s), f.per(h)

    def _gcdex(f, g: Self) -> tuple[Self, Self, Self]:
        """Extended Euclidean algorithm, if univariate. """
        s, t, h = dup_gcdex(f._rep, g._rep, cast("Field[Any]", f.dom))
        return f.per(s), f.per(t), f.per(h)

    def _invert(f, g: Self) -> Self:
        """Invert ``f`` modulo ``g``, if possible. """
        s = dup_invert(f._rep, g._rep, cast("Field[Any]", f.dom))
        return f.per(s)

    def _revert(f, n: int) -> Self:
        """Compute ``f**(-1)`` mod ``x**n``. """
        return f.per(_dmp(dup_revert(f._rep, n, f.dom)))

    def _subresultants(f, g: Self) -> list[Self]:
        """Computes subresultant PRS sequence of ``f`` and ``g``. """
        R = dmp_subresultants(f._rep, g._rep, f.lev, f.dom)
        return list(map(f.per, R))

    def _resultant_includePRS(f, g: Self) -> tuple[DMP[Er] | Er, list[DMP[Er]]]:
        """Computes resultant of ``f`` and ``g`` via PRS. """
        res, R = dmp_resultant(f._rep, g._rep, f.lev, f.dom, includePRS=True)
        # XXX: resultant returns a domain element at level 0...
        if f.lev:
            res = f.new(res, f.dom, f.lev - 1) # type: ignore
        return res, list(map(f.per, R)) # type: ignore

    def _resultant(f, g: Self) -> DMP[Er] | Er: