Skip to content

Fix AttributeError in PowerSeriesRing for division #39713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/sage/categories/commutative_rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sage.categories.category_with_axiom import CategoryWithAxiom
from sage.categories.cartesian_product import CartesianProductsCategory
from sage.structure.sequence import Sequence
from sage.structure.element import coercion_model


class CommutativeRings(CategoryWithAxiom):
Expand Down Expand Up @@ -539,6 +540,41 @@ def derivation(self, arg=None, twist=None):
codomain = self
return self.derivation_module(codomain, twist=twist)(arg)

def _pseudo_fraction_field(self):
r"""
This method is used by the coercion model to determine if `a / b`
should be treated as `a * (1/b)`, for example when dividing an element
of `\ZZ[x]` by an element of `\ZZ`.

The default is to return the same value as ``self.fraction_field()``,
but it may return some other domain in which division is usually
defined (for example, ``\ZZ/n\ZZ`` for possibly composite `n`).

EXAMPLES::

sage: ZZ._pseudo_fraction_field()
Rational Field
sage: ZZ['x']._pseudo_fraction_field()
Fraction Field of Univariate Polynomial Ring in x over Integer Ring
sage: Integers(15)._pseudo_fraction_field()
Ring of integers modulo 15
sage: Integers(15).fraction_field()
Traceback (most recent call last):
...
TypeError: self must be an integral domain.

TESTS::

sage: R.<x> = QQ[[]]
sage: S.<y> = R[[]]
sage: parent(y/(1+x))
Power Series Ring in y over Laurent Series Ring in x over Rational Field
"""
try:
return self.fraction_field()
except (NotImplementedError, TypeError):
return coercion_model.division_parent(self)

class ElementMethods:
pass

Expand Down
16 changes: 16 additions & 0 deletions src/sage/categories/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,22 @@
"""
return self

def _pseudo_fraction_field(self):
"""
The fraction field of ``self`` is always available as ``self``.

EXAMPLES::

sage: QQ._pseudo_fraction_field()

Check warning on line 537 in src/sage/categories/fields.py

View check run for this annotation

Codecov / codecov/patch

src/sage/categories/fields.py#L537

Added line #L537 was not covered by tests
Rational Field
sage: K = GF(5)
sage: K._pseudo_fraction_field()
Finite Field of size 5
sage: K._pseudo_fraction_field() is K
True
"""
return self

def ideal(self, *gens, **kwds):
"""
Return the ideal generated by ``gens``.
Expand Down
Loading