From ff2e83e57fd33a6d11de74f41141f584d37e08ef Mon Sep 17 00:00:00 2001 From: Sebastian Oehms Date: Sat, 5 Mar 2022 15:36:40 +0100 Subject: [PATCH 1/5] 33463: initial version --- src/sage/rings/localization.py | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 43705ce65cf..823c2a05046 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -156,6 +156,7 @@ AUTHORS: - Sebastian Oehms 2019-12-09: initial version. +- Sebastian Oehms 2022-03-05: fix some corner cases and add :meth:`factor` (:trac:`33463`) """ @@ -362,6 +363,26 @@ def _lmul_(self, c): """ return self.parent()._fraction_to_element(self._value * c) + def factor(self): + r""" + + EXAMPLES:: + + sage: P. = QQ['x, y'] + sage: L = P.localization(X-Y) + sage: x, y = L.gens() + sage: p = (x^2 - y^2)/(x-y)^2 + sage: p.factor() + (1/(x - y)) * (x + y) + """ + num = self._value.numerator() + den = self._value.denominator() + F = num.factor() + P = self.parent() + fac = [(P(f), e) for (f,e) in F] + from sage.structure.factorization import Factorization + return Factorization(fac, unit=~P(den)*F.unit()) + def _im_gens_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: @@ -589,7 +610,20 @@ class Localization(IntegralDomain, UniqueRepresentation): ... ValueError: factor x^2 + 2 of denominator is not a unit + sage: Lau. = LaurentPolynomialRing(ZZ) + sage: LauL = Lau.localization(u+1) + sage: LauL(~u).parent() + Multivariate Polynomial Ring in u, v over Integer Ring localized at (v, u, u + 1) + More examples will be shown typing ``sage.rings.localization?`` + + TESTS: + + Check that :trac:`33463` is fixed:: + + sage: R = ZZ.localization(5) + sage: R.localization(~5) + Integer Ring localized at (5,) """ Element = LocalizationElement @@ -612,8 +646,14 @@ def __init__(self, base_ring, additional_units, names=None, normalize=True, cate if not type(additional_units) is list: additional_units = [additional_units] + from sage.rings.polynomial.laurent_polynomial_ring import is_LaurentPolynomialRing + if is_LaurentPolynomialRing(base_ring): + additional_units += list(base_ring.gens()) + base_ring = base_ring.polynomial_ring() + if isinstance(base_ring, Localization): # don't allow recursive constructions + additional_units = [au for au in additional_units if not ~au in base_ring._additional_units] # :trac:`33463` additional_units += base_ring._additional_units base_ring = base_ring.base_ring() @@ -791,7 +831,18 @@ def _cut_off_additional_units_from_base_ring_element(self, x): 1 sage: L._cut_off_additional_units_from_base_ring_element(x*z) 1 + + TESTS: + + check that :trac:`33463` is fixed: + + sage: L = ZZ.localization(5) + sage: L(0).is_unit() + False """ + if x.is_zero() or x.numerator().is_unit(): + # treat corner cases + return x add_units = self._additional_units res = x for au in add_units: From 5df7f557218f93f06506453162ca0463b8c0609f Mon Sep 17 00:00:00 2001 From: Sebastian Oehms Date: Sun, 6 Mar 2022 23:17:38 +0100 Subject: [PATCH 2/5] 33464: add kw proof to factor and style fixes --- src/sage/rings/localization.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 823c2a05046..4e549341689 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -363,9 +363,14 @@ def _lmul_(self, c): """ return self.parent()._fraction_to_element(self._value * c) - def factor(self): + def factor(self, proof=None): r""" + INPUT: + + - ``proof`` -- optional (default ``None``). If given it is passed + to the corresponding method of the numerator of ``self``. + EXAMPLES:: sage: P. = QQ['x, y'] @@ -377,9 +382,12 @@ def factor(self): """ num = self._value.numerator() den = self._value.denominator() - F = num.factor() - P = self.parent() - fac = [(P(f), e) for (f,e) in F] + if proof is not None: + F = num.factor(proof=proof) + else: + F = num.factor() + P = self.parent() + fac = [(P(f), e) for (f, e) in F] from sage.structure.factorization import Factorization return Factorization(fac, unit=~P(den)*F.unit()) @@ -653,7 +661,7 @@ def __init__(self, base_ring, additional_units, names=None, normalize=True, cate if isinstance(base_ring, Localization): # don't allow recursive constructions - additional_units = [au for au in additional_units if not ~au in base_ring._additional_units] # :trac:`33463` + additional_units = [au for au in additional_units if ~au not in base_ring._additional_units] # :trac:`33463` additional_units += base_ring._additional_units base_ring = base_ring.base_ring() @@ -834,7 +842,7 @@ def _cut_off_additional_units_from_base_ring_element(self, x): TESTS: - check that :trac:`33463` is fixed: + Check that :trac:`33463` is fixed:: sage: L = ZZ.localization(5) sage: L(0).is_unit() From ceeeebc796ba03e2f1617bde932449584d399cf2 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 7 Mar 2022 08:01:17 +0100 Subject: [PATCH 3/5] 33463: add missing description of meth factor --- src/sage/rings/localization.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 4e549341689..f9e490e2c1a 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -365,6 +365,7 @@ def _lmul_(self, c): def factor(self, proof=None): r""" + Return the factorization of this polynomial. INPUT: From d48dc281ef58374105106c381c56033966f7f747 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 7 Mar 2022 08:12:34 +0100 Subject: [PATCH 4/5] 33463: once again --- src/sage/rings/localization.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index f9e490e2c1a..794524a6d4a 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -369,8 +369,8 @@ def factor(self, proof=None): INPUT: - - ``proof`` -- optional (default ``None``). If given it is passed - to the corresponding method of the numerator of ``self``. + - ``proof`` -- optional if given it is passed to the + corresponding method of the numerator of ``self`` EXAMPLES:: From fc1865ab76a21ce76a621ee0b6a678a815138a02 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 7 Mar 2022 18:38:24 +0100 Subject: [PATCH 5/5] 33463: another one --- src/sage/rings/localization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 794524a6d4a..5f9e506bdff 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -369,7 +369,7 @@ def factor(self, proof=None): INPUT: - - ``proof`` -- optional if given it is passed to the + - ``proof`` -- (optional) if given it is passed to the corresponding method of the numerator of ``self`` EXAMPLES::