diff --git a/src/sage/categories/commutative_rings.py b/src/sage/categories/commutative_rings.py index 961ca17d629..d1e66341c27 100644 --- a/src/sage/categories/commutative_rings.py +++ b/src/sage/categories/commutative_rings.py @@ -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): @@ -539,6 +540,40 @@ 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. = QQ[[]] + sage: S. = 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 diff --git a/src/sage/categories/fields.py b/src/sage/categories/fields.py index 9c7eca5c82c..7fe8f703a4d 100644 --- a/src/sage/categories/fields.py +++ b/src/sage/categories/fields.py @@ -527,6 +527,22 @@ def fraction_field(self): True """ return self + + def _pseudo_fraction_field(self): + """ + The fraction field of ``self`` is always available as ``self``. + + EXAMPLES:: + + sage: QQ._pseudo_fraction_field() + 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): """