From b7480975f2b66e2c8a13a9d1eafecc06605edc1f Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 30 Apr 2014 00:41:52 -0700 Subject: [PATCH 01/11] Fix hash for unreduced fraction field elements. --- src/sage/rings/fraction_field_element.pyx | 66 ++++++++++++++++++++--- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index bcb6509f0e3..524c91fcf8b 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -91,6 +91,7 @@ cdef class FractionFieldElement(FieldElement): """ cdef object __numerator cdef object __denominator + cdef bint _is_reduced def __init__(self, parent, numerator, denominator=1, coerce=True, reduce=True): @@ -157,7 +158,7 @@ cdef class FractionFieldElement(FieldElement): nden = codomain.coerce(self.__denominator._im_gens_(codomain, im_gens)) return codomain.coerce(nnum/nden) - def reduce(self): + cpdef reduce(self): """ Divides out the gcd of the numerator and denominator. @@ -173,6 +174,8 @@ cdef class FractionFieldElement(FieldElement): sage: f.reduce(); f x + 1.0 """ + if self._is_reduced: + return try: g = self.__numerator.gcd(self.__denominator) if not g.is_unit(): @@ -189,6 +192,7 @@ cdef class FractionFieldElement(FieldElement): pass self.__numerator = num self.__denominator = den + self._is_reduced = True except AttributeError: raise ArithmeticError("unable to reduce because lack of gcd or quo_rem algorithm") except TypeError: @@ -196,6 +200,22 @@ cdef class FractionFieldElement(FieldElement): except NotImplementedError: raise ArithmeticError("unable to reduce because gcd algorithm not implemented on input") + cpdef normalize(self): + """ + Returns a normalized representation of self. + + In particular, for any a == b, after normalization they will have the + same numerator and denominator. + + EXAMPLES:: + + sage: R. = Frac(ZZ['x']) + sage: s = (2*x + 2) / (4*x) + sage: s.normalize(); s + (x + 1)/(2*x) + """ + self.reduce() + def __copy__(self): """ Make a copy of ``self``. @@ -341,17 +361,31 @@ cdef class FractionFieldElement(FieldElement): 1 sage: hash(R(1)/R(2))==hash(1/2) True + + Ensure normalization is done before hashing the numerator and + denominator, fixing trac #16268:: + + sage: Ku. = FractionField(PolynomialRing(QQ,'u')) + sage: a = 27*u^2+81*u+243 + sage: b = 27*u-81 + sage: c = u^2 + 3*u + 9 + sage: d = u-3 + sage: s = a/b + sage: t = c/d + sage: s==t + True + sage: len(Set([s,t])) + 1 """ # This is same algorithm as used for members of QQ #cdef long n, d + self.normalize() n = hash(self.__numerator) d = hash(self.__denominator) if d == 1: return n - n = n ^ d - if n == -1: - return -2 - return n + else: + return n ^ d def __call__(self, *x, **kwds): """ @@ -1027,7 +1061,7 @@ cdef class FractionFieldElement(FieldElement): raise NotImplementedError -class FractionFieldElement_1poly_field(FractionFieldElement): +cdef class FractionFieldElement_1poly_field(FractionFieldElement): """ A fraction field element where the parent is the fraction field of a univariate polynomial ring. @@ -1070,6 +1104,26 @@ class FractionFieldElement_1poly_field(FractionFieldElement): L.sort() return L + cpdef normalize(self): + """ + Returns a normalized representation of self. + + In particular, for any a == b, after normalization they will have the + same numerator and denominator. + + EXAMPLES:: + + sage: R. = QQ[] + sage: s = (1 + x) / (2*x); s + (x + 1)/(2*x) + sage: s.normalize(); s + (1/2*x + 1/2)/x + """ + self.reduce() + leading = self.__denominator.leading_coefficient() + if leading != 1: + self.__numerator /= leading + self.__denominator /= leading def make_element(parent, numerator, denominator): """ From 2850652793ef87f2b261d267ff521e8d925b1f6f Mon Sep 17 00:00:00 2001 From: Erik Massop Date: Fri, 2 May 2014 15:57:02 +0200 Subject: [PATCH 02/11] Fix documentation of normalize --- src/sage/rings/fraction_field_element.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 524c91fcf8b..4341d2b8a5d 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -202,7 +202,7 @@ cdef class FractionFieldElement(FieldElement): cpdef normalize(self): """ - Returns a normalized representation of self. + Picks a normalized representation of self. In particular, for any a == b, after normalization they will have the same numerator and denominator. @@ -1106,7 +1106,7 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): cpdef normalize(self): """ - Returns a normalized representation of self. + Picks a normalized representation of self. In particular, for any a == b, after normalization they will have the same numerator and denominator. From 26c87d3bc0909edb33530f0b649f79b8d79871ac Mon Sep 17 00:00:00 2001 From: Erik Massop Date: Sun, 4 May 2014 18:51:45 +0200 Subject: [PATCH 03/11] Fix doctest FractionFieldElement_1poly_field is a cdef class now --- src/sage/rings/fraction_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 201e132bb73..a04957ec5fd 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -862,7 +862,7 @@ def __init__(self, R, sage: R. = QQ[]; K = R.fraction_field() sage: K._element_class - + """ FractionField_generic.__init__(self, R, element_class) From 78b59908725d9c98db66cdf2af8dadd2c719f5f0 Mon Sep 17 00:00:00 2001 From: Erik Massop Date: Sun, 4 May 2014 18:58:58 +0200 Subject: [PATCH 04/11] More careful hashing of FractionFieldElement * Remove normalize from general FractionFieldElement * Call reduce automatically only for exact rings * Refuse returning hash when independence of representative uncertain --- src/sage/rings/fraction_field_element.pyx | 81 ++++++++++++----------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 4341d2b8a5d..c355d5954a7 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -162,6 +162,8 @@ cdef class FractionFieldElement(FieldElement): """ Divides out the gcd of the numerator and denominator. + If the denominator becomes a unit, it becomes 1. + Automatically called for exact rings, but because it may be numerically unstable for inexact rings it must be called manually in that case. @@ -200,22 +202,6 @@ cdef class FractionFieldElement(FieldElement): except NotImplementedError: raise ArithmeticError("unable to reduce because gcd algorithm not implemented on input") - cpdef normalize(self): - """ - Picks a normalized representation of self. - - In particular, for any a == b, after normalization they will have the - same numerator and denominator. - - EXAMPLES:: - - sage: R. = Frac(ZZ['x']) - sage: s = (2*x + 2) / (4*x) - sage: s.normalize(); s - (x + 1)/(2*x) - """ - self.reduce() - def __copy__(self): """ Make a copy of ``self``. @@ -362,30 +348,15 @@ cdef class FractionFieldElement(FieldElement): sage: hash(R(1)/R(2))==hash(1/2) True - Ensure normalization is done before hashing the numerator and - denominator, fixing trac #16268:: - - sage: Ku. = FractionField(PolynomialRing(QQ,'u')) - sage: a = 27*u^2+81*u+243 - sage: b = 27*u-81 - sage: c = u^2 + 3*u + 9 - sage: d = u-3 - sage: s = a/b - sage: t = c/d - sage: s==t - True - sage: len(Set([s,t])) - 1 """ - # This is same algorithm as used for members of QQ - #cdef long n, d - self.normalize() - n = hash(self.__numerator) - d = hash(self.__denominator) - if d == 1: - return n - else: - return n ^ d + if self._parent.is_exact(): + try: + self.reduce() + except ArithmeticError: + pass + if self.__denominator.is_one(): + return hash(self.__numerator) + raise NotImplementedError("Do not know how to hash elements of general fraction field") def __call__(self, *x, **kwds): """ @@ -1125,6 +1096,38 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): self.__numerator /= leading self.__denominator /= leading + def __hash__(self): + """ + This function hashes in a special way to ensure that elements of + a ring `R` and their images in a fraction field of `R` have the same + hash. This enables them to be used as keys interchangeably in a + dictionary (since ``==`` will claim them equal). + + Ensure normalization is done before hashing the numerator and + denominator, fixing trac #16268:: + + sage: Ku. = FractionField(PolynomialRing(QQ,'u')) + sage: a = 27*u^2+81*u+243 + sage: b = 27*u-81 + sage: c = u^2 + 3*u + 9 + sage: d = u-3 + sage: s = a/b + sage: t = c/d + sage: s==t + True + sage: len(Set([s,t])) + 1 + """ + # This is same algorithm as used for members of QQ + #cdef long n, d + self.normalize() + n = hash(self.__numerator) + d = hash(self.__denominator) + if d == 1: + return n + else: + return n ^ d + def make_element(parent, numerator, denominator): """ Used for unpickling :class:`FractionFieldElement` objects (and subclasses). From e7689732921af17a0f100651615e429d9711979e Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Mon, 23 Apr 2018 12:11:14 +0200 Subject: [PATCH 05/11] slightly simplify/robustify FractionFieldElement.reduce() --- src/sage/rings/fraction_field_element.pyx | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index c355d5954a7..507f4f56a0d 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -181,19 +181,8 @@ cdef class FractionFieldElement(FieldElement): try: g = self.__numerator.gcd(self.__denominator) if not g.is_unit(): - num, _ = self.__numerator.quo_rem(g) - den, _ = self.__denominator.quo_rem(g) - else: - num = self.__numerator - den = self.__denominator - if not den.is_one() and den.is_unit(): - try: - num *= den.inverse_of_unit() - den = den.parent().one() - except Exception: - pass - self.__numerator = num - self.__denominator = den + self.__numerator //= g + self.__denominator //= g self._is_reduced = True except AttributeError: raise ArithmeticError("unable to reduce because lack of gcd or quo_rem algorithm") @@ -201,6 +190,14 @@ cdef class FractionFieldElement(FieldElement): raise ArithmeticError("unable to reduce because gcd algorithm doesn't work on input") except NotImplementedError: raise ArithmeticError("unable to reduce because gcd algorithm not implemented on input") + if not self.__denominator.is_one() and self.__denominator.is_unit(): + try: + inv = self.__denominator.inverse_of_unit() + except Exception: + pass + else: + self.__numerator *= inv + self.__denominator = self.__denominator.parent().one() def __copy__(self): """ From 029346f6b30c052156b56572248145344e7e8bc9 Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Mon, 23 Apr 2018 12:18:25 +0200 Subject: [PATCH 06/11] FractionFieldElement: merge reduce() and normalize() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For elements of fields like ℚ(x,y)(t), it is typically much better for performance to always normalize the leading coefficients. Let's do it by default instead of requiring users to call a separate normalization method. --- src/sage/rings/fraction_field_element.pyx | 39 +++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 507f4f56a0d..89ce2ef1bb7 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -160,9 +160,12 @@ cdef class FractionFieldElement(FieldElement): cpdef reduce(self): """ - Divides out the gcd of the numerator and denominator. + Reduce this fraction. - If the denominator becomes a unit, it becomes 1. + Divides out the gcd of the numerator and denominator. If the + denominator becomes a unit, it becomes 1. Additionally, depending on + the base ring, the leading coefficients of the numerator and the + denominator may be normalized to 1. Automatically called for exact rings, but because it may be numerically unstable for inexact rings it must be called manually @@ -1032,7 +1035,7 @@ cdef class FractionFieldElement(FieldElement): cdef class FractionFieldElement_1poly_field(FractionFieldElement): """ A fraction field element where the parent is the fraction field of a - univariate polynomial ring. + univariate polynomial ring over a field. Many of the functions here are included for coherence with number fields. """ @@ -1072,26 +1075,31 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): L.sort() return L - cpdef normalize(self): + cpdef reduce(self): """ - Picks a normalized representation of self. + Pick a normalized representation of self. In particular, for any a == b, after normalization they will have the same numerator and denominator. - EXAMPLES:: + EXAMPLES: + + For univariate rational functions over a field, we have:: sage: R. = QQ[] - sage: s = (1 + x) / (2*x); s - (x + 1)/(2*x) - sage: s.normalize(); s + sage: (2 + 2*x) / (4*x) # indirect doctest (1/2*x + 1/2)/x + + Compare with:: + + sage: R. = ZZ[] + sage: (2 + 2*x) / (4*x) + (x + 1)/(2*x) """ - self.reduce() - leading = self.__denominator.leading_coefficient() - if leading != 1: - self.__numerator /= leading - self.__denominator /= leading + super(self.__class__, self).reduce() + invlc = ~self.__denominator.leading_coefficient() + self.__denominator = self.__denominator.monic() + self.__numerator *= invlc def __hash__(self): """ @@ -1116,8 +1124,7 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): 1 """ # This is same algorithm as used for members of QQ - #cdef long n, d - self.normalize() + self.reduce() n = hash(self.__numerator) d = hash(self.__denominator) if d == 1: From 80f18f0f0e1936c821db76f9b02576dde26f9f97 Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Mon, 23 Apr 2018 14:14:58 +0200 Subject: [PATCH 07/11] Tweak fraction field element hashing - merge back FractionFieldElement_1poly_field.__hash__() into FractionFieldElement.__hash__() (partial revert of 198c0596630bb4ecc200e62c55715441e6f38d5c); - let exceptions raised by reduce() propagate: this will typically be more informative than raising a new exception; - hash unreduced fractions without complaining over inexact rings, as a compatibility tradeoff. --- src/sage/rings/fraction_field_element.pyx | 68 +++++++++++------------ 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 89ce2ef1bb7..4d6c2d6c4af 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -348,15 +348,40 @@ cdef class FractionFieldElement(FieldElement): sage: hash(R(1)/R(2))==hash(1/2) True + Check that :trac:`16268` is fixed:: + + sage: ku. = FractionField(PolynomialRing(QQ,'u')) + sage: a = 27*u^2+81*u+243 + sage: b = 27*u-81 + sage: c = u^2 + 3*u + 9 + sage: d = u-3 + sage: s = a/b + sage: t = c/d + sage: s == t + True + sage: len(set([s,t])) + 1 """ - if self._parent.is_exact(): - try: - self.reduce() - except ArithmeticError: - pass if self.__denominator.is_one(): + # Handle this case even over rings that don't support reduction, to + # avoid breaking existing code that carelessly mixes p and p/1 return hash(self.__numerator) - raise NotImplementedError("Do not know how to hash elements of general fraction field") + if self._parent.is_exact(): + # May fail; let the exception propagate then. + # (In contrast, over inexact rings, we hash unreduced fractions + # without complaining. This is not ideal, but there is code in Sage + # that uses dictionaries indexed by rational functions with + # floating-point coefficients, and since the equality test involves + # potentially inexact operations, there would be compatibility + # issues even if we didn't...) + self.reduce() + # Same algorithm as for elements of QQ + n = hash(self.__numerator) + d = hash(self.__denominator) + if d == 1: + return n + else: + return n ^ d def __call__(self, *x, **kwds): """ @@ -1101,37 +1126,6 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): self.__denominator = self.__denominator.monic() self.__numerator *= invlc - def __hash__(self): - """ - This function hashes in a special way to ensure that elements of - a ring `R` and their images in a fraction field of `R` have the same - hash. This enables them to be used as keys interchangeably in a - dictionary (since ``==`` will claim them equal). - - Ensure normalization is done before hashing the numerator and - denominator, fixing trac #16268:: - - sage: Ku. = FractionField(PolynomialRing(QQ,'u')) - sage: a = 27*u^2+81*u+243 - sage: b = 27*u-81 - sage: c = u^2 + 3*u + 9 - sage: d = u-3 - sage: s = a/b - sage: t = c/d - sage: s==t - True - sage: len(Set([s,t])) - 1 - """ - # This is same algorithm as used for members of QQ - self.reduce() - n = hash(self.__numerator) - d = hash(self.__denominator) - if d == 1: - return n - else: - return n ^ d - def make_element(parent, numerator, denominator): """ Used for unpickling :class:`FractionFieldElement` objects (and subclasses). From 1153b5dfe3f26bf9b1a2b64e0a3c709a672370ad Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Mon, 23 Apr 2018 13:56:46 +0200 Subject: [PATCH 08/11] #16268 boring doctest updates --- src/sage/categories/functor.pyx | 2 +- src/sage/coding/linear_code.py | 2 +- src/sage/combinat/sf/dual.py | 2 +- src/sage/combinat/sf/jack.py | 40 +++++++------ src/sage/combinat/sf/sfa.py | 6 +- .../arithmetic_dynamics/projective_ds.py | 2 +- src/sage/groups/perm_gps/permgroup.py | 6 +- ...otics_multivariate_generating_functions.py | 3 +- src/sage/rings/cfinite_sequence.py | 56 +++++++++---------- src/sage/rings/fraction_field_element.pyx | 4 +- .../rings/polynomial/laurent_polynomial.pyx | 2 +- .../polynomial/polynomial_rational_flint.pyx | 2 +- src/sage/rings/polynomial/polynomial_ring.py | 2 +- .../schemes/elliptic_curves/constructor.py | 2 +- .../schemes/elliptic_curves/ell_generic.py | 2 +- .../schemes/projective/projective_space.py | 2 +- src/sage/structure/element.pyx | 2 +- src/sage/tests/french_book/polynomes.py | 2 +- 18 files changed, 72 insertions(+), 67 deletions(-) diff --git a/src/sage/categories/functor.pyx b/src/sage/categories/functor.pyx index 6d193f2971d..cf6314e47e5 100644 --- a/src/sage/categories/functor.pyx +++ b/src/sage/categories/functor.pyx @@ -262,7 +262,7 @@ cdef class Functor(SageObject): Ring endomorphism of Finite Field in a of size 5^2 Defn: a |--> 4*a + 1 sage: fF((a^2+a)*t^2/(a*t - a^2)) - 3*a*t^2/((4*a + 1)*t + a + 1) + ((4*a + 2)*t^2)/(t + a + 4) """ try: diff --git a/src/sage/coding/linear_code.py b/src/sage/coding/linear_code.py index 89db3687501..cacbaabce93 100644 --- a/src/sage/coding/linear_code.py +++ b/src/sage/coding/linear_code.py @@ -3499,7 +3499,7 @@ def zeta_function(self, name="T"): sage: C = codes.HammingCode(GF(2), 3) sage: C.zeta_function() - (2/5*T^2 + 2/5*T + 1/5)/(2*T^2 - 3*T + 1) + (1/5*T^2 + 1/5*T + 1/10)/(T^2 - 3/2*T + 1/2) """ P = self.zeta_polynomial() q = (self.base_ring()).characteristic() diff --git a/src/sage/combinat/sf/dual.py b/src/sage/combinat/sf/dual.py index 77f22a58ccb..cb73aabc57a 100644 --- a/src/sage/combinat/sf/dual.py +++ b/src/sage/combinat/sf/dual.py @@ -735,7 +735,7 @@ def scalar_hl(self, x): sage: h = m.dual_basis(scalar=zee) sage: a = h([2,1]) sage: a.scalar_hl(a) - (t + 2)/(-t^4 + 2*t^3 - 2*t + 1) + (-t - 2)/(t^4 - 2*t^3 + 2*t - 1) """ return self._dual.scalar_hl(x) diff --git a/src/sage/combinat/sf/jack.py b/src/sage/combinat/sf/jack.py index 8655072da19..f58a4850173 100644 --- a/src/sage/combinat/sf/jack.py +++ b/src/sage/combinat/sf/jack.py @@ -214,9 +214,9 @@ def P(self): :: sage: JP(JQ([2,1])) - ((t+2)/(2*t^3+t^2))*JackP[2, 1] + ((1/2*t+1)/(t^3+1/2*t^2))*JackP[2, 1] sage: JP(JQ([3])) - ((2*t^2+3*t+1)/(6*t^3))*JackP[3] + ((1/3*t^2+1/2*t+1/6)/t^3)*JackP[3] sage: JP(JQ([1,1,1])) (6/(t^3+3*t^2+2*t))*JackP[1, 1, 1] @@ -266,13 +266,13 @@ def Q(self): sage: JQ = Sym.jack().Q() sage: JP = Sym.jack().P() sage: JQ(sum(JP(p) for p in Partitions(3))) - (1/6*t^3+1/2*t^2+1/3*t)*JackQ[1, 1, 1] + ((2*t^3+t^2)/(t+2))*JackQ[2, 1] + (6*t^3/(2*t^2+3*t+1))*JackQ[3] + (1/6*t^3+1/2*t^2+1/3*t)*JackQ[1, 1, 1] + ((2*t^3+t^2)/(t+2))*JackQ[2, 1] + (3*t^3/(t^2+3/2*t+1/2))*JackQ[3] :: sage: s = Sym.schur() sage: JQ(s([3])) # indirect doctest - (1/6*t^3-1/2*t^2+1/3*t)*JackQ[1, 1, 1] + ((2*t^3-2*t^2)/(t+2))*JackQ[2, 1] + (6*t^3/(2*t^2+3*t+1))*JackQ[3] + (1/6*t^3-1/2*t^2+1/3*t)*JackQ[1, 1, 1] + ((2*t^3-2*t^2)/(t+2))*JackQ[2, 1] + (3*t^3/(t^2+3/2*t+1/2))*JackQ[3] sage: JQ(s([2,1])) (1/3*t^3-1/3*t)*JackQ[1, 1, 1] + ((2*t^3+t^2)/(t+2))*JackQ[2, 1] sage: JQ(s([1,1,1])) @@ -329,15 +329,15 @@ def J(self): sage: JJ = Sym.jack().J() sage: JP = Sym.jack().P() sage: JJ(sum(JP(p) for p in Partitions(3))) - 1/6*JackJ[1, 1, 1] + (1/(t+2))*JackJ[2, 1] + (1/(2*t^2+3*t+1))*JackJ[3] + 1/6*JackJ[1, 1, 1] + (1/(t+2))*JackJ[2, 1] + (1/2/(t^2+3/2*t+1/2))*JackJ[3] :: sage: s = Sym.schur() sage: JJ(s([3])) # indirect doctest - ((t^2-3*t+2)/(6*t^2+18*t+12))*JackJ[1, 1, 1] + ((2*t-2)/(2*t^2+5*t+2))*JackJ[2, 1] + (1/(2*t^2+3*t+1))*JackJ[3] + ((1/6*t^2-1/2*t+1/3)/(t^2+3*t+2))*JackJ[1, 1, 1] + ((t-1)/(t^2+5/2*t+1))*JackJ[2, 1] + (1/2/(t^2+3/2*t+1/2))*JackJ[3] sage: JJ(s([2,1])) - ((t-1)/(3*t+6))*JackJ[1, 1, 1] + (1/(t+2))*JackJ[2, 1] + ((1/3*t-1/3)/(t+2))*JackJ[1, 1, 1] + (1/(t+2))*JackJ[2, 1] sage: JJ(s([1,1,1])) 1/6*JackJ[1, 1, 1] """ @@ -715,12 +715,12 @@ def _multiply(self, left, right): sage: JJ([1])^2 # indirect doctest (t/(t+1))*JackJ[1, 1] + (1/(t+1))*JackJ[2] sage: JJ([2])^2 - (2*t^2/(2*t^2+3*t+1))*JackJ[2, 2] + (4*t/(3*t^2+4*t+1))*JackJ[3, 1] + ((t+1)/(6*t^2+5*t+1))*JackJ[4] + (t^2/(t^2+3/2*t+1/2))*JackJ[2, 2] + (4/3*t/(t^2+4/3*t+1/3))*JackJ[3, 1] + ((1/6*t+1/6)/(t^2+5/6*t+1/6))*JackJ[4] sage: JQ = SymmetricFunctions(FractionField(QQ['t'])).jack().Q() sage: JQ([1])^2 # indirect doctest JackQ[1, 1] + (2/(t+1))*JackQ[2] sage: JQ([2])^2 - JackQ[2, 2] + (2/(t+1))*JackQ[3, 1] + ((6*t+6)/(6*t^2+5*t+1))*JackQ[4] + JackQ[2, 2] + (2/(t+1))*JackQ[3, 1] + ((t+1)/(t^2+5/6*t+1/6))*JackQ[4] """ return self( self._P(left)*self._P(right) ) @@ -889,11 +889,12 @@ def _m_cache(self, n): sage: l(JP._m_to_self_cache[3]) [([1, 1, 1], [([1, 1, 1], 1)]), ([2, 1], [([1, 1, 1], -6/(t + 2)), ([2, 1], 1)]), - ([3], [([1, 1, 1], 6/(t^2 + 3*t + 2)), ([2, 1], -3/(2*t + 1)), ([3], 1)])] + ([3], [([1, 1, 1], 6/(t^2 + 3*t + 2)), ([2, 1], -3/2/(t + 1/2)), ([3], 1)])] sage: l(JP._self_to_m_cache[3]) [([1, 1, 1], [([1, 1, 1], 1)]), ([2, 1], [([1, 1, 1], 6/(t + 2)), ([2, 1], 1)]), - ([3], [([1, 1, 1], 6/(2*t^2 + 3*t + 1)), ([2, 1], 3/(2*t + 1)), ([3], 1)])] + ([3], + [([1, 1, 1], 3/(t^2 + 3/2*t + 1/2)), ([2, 1], 3/2/(t + 1/2)), ([3], 1)])] """ if n in self._self_to_m_cache: return @@ -1002,9 +1003,9 @@ def scalar_jack_basis(self, part1, part2 = None): sage: JP.scalar_jack_basis(Partition([2,1]), Partition([1,1,1])) 0 sage: JP._normalize_coefficients(JP.scalar_jack_basis(Partition([3,2,1]), Partition([3,2,1]))) - (12*t^6 + 20*t^5 + 11*t^4 + 2*t^3)/(2*t^3 + 11*t^2 + 20*t + 12) + (6*t^6 + 10*t^5 + 11/2*t^4 + t^3)/(t^3 + 11/2*t^2 + 10*t + 6) sage: JJ(JP[3,2,1]).scalar_jack(JP[3,2,1]) - (12*t^6 + 20*t^5 + 11*t^4 + 2*t^3)/(2*t^3 + 11*t^2 + 20*t + 12) + (6*t^6 + 10*t^5 + 11/2*t^4 + t^3)/(t^3 + 11/2*t^2 + 10*t + 6) With a single argument, takes `part2 = part1`:: @@ -1035,7 +1036,7 @@ def scalar_jack(self, x, t=None): sage: JP = SymmetricFunctions(FractionField(QQ['t'])).jack().P() sage: l = [JP(p) for p in Partitions(3)] sage: matrix([[a.scalar_jack(b) for a in l] for b in l]) - [ 6*t^3/(2*t^2 + 3*t + 1) 0 0] + [3*t^3/(t^2 + 3/2*t + 1/2) 0 0] [ 0 (2*t^3 + t^2)/(t + 2) 0] [ 0 0 1/6*t^3 + 1/2*t^2 + 1/3*t] """ @@ -1195,9 +1196,14 @@ def _h_cache(self, n): [([1, 1], [([1, 1], 1), ([2], 2/(t + 1))]), ([2], [([2], 1)])] sage: JQp._h_cache(3) sage: l(JQp._h_to_self_cache[3]) - [([1, 1, 1], [([1, 1, 1], 1), ([2, 1], 6/(t + 2)), ([3], 6/(2*t^2 + 3*t + 1))]), ([2, 1], [([2, 1], 1), ([3], 3/(2*t + 1))]), ([3], [([3], 1)])] + [([1, 1, 1], + [([1, 1, 1], 1), ([2, 1], 6/(t + 2)), ([3], 3/(t^2 + 3/2*t + 1/2))]), + ([2, 1], [([2, 1], 1), ([3], 3/2/(t + 1/2))]), + ([3], [([3], 1)])] sage: l(JQp._self_to_h_cache[3]) - [([1, 1, 1], [([1, 1, 1], 1), ([2, 1], -6/(t + 2)), ([3], 6/(t^2 + 3*t + 2))]), ([2, 1], [([2, 1], 1), ([3], -3/(2*t + 1))]), ([3], [([3], 1)])] + [([1, 1, 1], [([1, 1, 1], 1), ([2, 1], -6/(t + 2)), ([3], 6/(t^2 + 3*t + 2))]), + ([2, 1], [([2, 1], 1), ([3], -3/2/(t + 1/2))]), + ([3], [([3], 1)])] """ if n in self._self_to_h_cache: return @@ -1291,7 +1297,7 @@ def coproduct_by_coercion( self, elt ): sage: Sym = SymmetricFunctions(QQ['t'].fraction_field()) sage: JQp = Sym.jack().Qp() sage: JQp[2,2].coproduct() #indirect doctest - JackQp[] # JackQp[2, 2] + (2*t/(t+1))*JackQp[1] # JackQp[2, 1] + JackQp[1, 1] # JackQp[1, 1] + ((4*t^3+8*t^2)/(2*t^3+5*t^2+4*t+1))*JackQp[2] # JackQp[2] + (2*t/(t+1))*JackQp[2, 1] # JackQp[1] + JackQp[2, 2] # JackQp[] + JackQp[] # JackQp[2, 2] + (2*t/(t+1))*JackQp[1] # JackQp[2, 1] + JackQp[1, 1] # JackQp[1, 1] + ((2*t^3+4*t^2)/(t^3+5/2*t^2+2*t+1/2))*JackQp[2] # JackQp[2] + (2*t/(t+1))*JackQp[2, 1] # JackQp[1] + JackQp[2, 2] # JackQp[] """ h = elt.parent().realization_of().h() parent = elt.parent() diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index b439700bea5..85da8a842c0 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -4468,9 +4468,9 @@ def scalar_jack(self, x, t=None): [ 0 0 0 0 384] sage: JQ = SymmetricFunctions(QQ['t'].fraction_field()).jack().Q() sage: matrix([[JQ(mu).scalar_jack(JQ(nu)) for nu in Partitions(3)] for mu in Partitions(3)]) - [(2*t^2 + 3*t + 1)/(6*t^3) 0 0] - [ 0 (t + 2)/(2*t^3 + t^2) 0] - [ 0 0 6/(t^3 + 3*t^2 + 2*t)] + [(1/3*t^2 + 1/2*t + 1/6)/t^3 0 0] + [ 0 (1/2*t + 1)/(t^3 + 1/2*t^2) 0] + [ 0 0 6/(t^3 + 3*t^2 + 2*t)] """ parent = self.parent() if t is None: diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index 421fd8d2f6a..a05a211a6a0 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -2571,7 +2571,7 @@ def automorphism_group(self, **kwds): sage: R. = ProjectiveSpace(QQ,1) sage: f = DynamicalSystem_projective([x^2-2*x*y-2*y^2, -2*x^2-2*x*y+y^2]) sage: f.automorphism_group(return_functions=True) - [x, 2/(2*x), -x - 1, -2*x/(2*x + 2), (-x - 1)/x, -1/(x + 1)] + [x, 1/x, -x - 1, -x/(x + 1), (-x - 1)/x, -1/(x + 1)] :: diff --git a/src/sage/groups/perm_gps/permgroup.py b/src/sage/groups/perm_gps/permgroup.py index 4c4958371ac..36648d97d6a 100644 --- a/src/sage/groups/perm_gps/permgroup.py +++ b/src/sage/groups/perm_gps/permgroup.py @@ -4058,10 +4058,10 @@ def molien_series(self): sage: G = SymmetricGroup(5) sage: G.molien_series() - 1/(-x^15 + x^14 + x^13 - x^10 - x^9 - x^8 + x^7 + x^6 + x^5 - x^2 - x + 1) + -1/(x^15 - x^14 - x^13 + x^10 + x^9 + x^8 - x^7 - x^6 - x^5 + x^2 + x - 1) sage: G = SymmetricGroup(3) sage: G.molien_series() - 1/(-x^6 + x^5 + x^4 - x^2 - x + 1) + -1/(x^6 - x^5 - x^4 + x^2 + x - 1) Some further tests (after :trac:`15817`):: @@ -4138,7 +4138,7 @@ def poincare_series(self, p=2, n=10): (x^2 + 1)/(x^4 - x^3 - x + 1) sage: G = SymmetricGroup(3) sage: G.poincare_series(2,10) # optional - gap_packages - 1/(-x + 1) + -1/(x - 1) AUTHORS: diff --git a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py index 14cfc0a324b..9629a44c58e 100644 --- a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +++ b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py @@ -756,8 +756,7 @@ def univariate_decomposition(self): sage: FFPD = FractionWithFactoredDenominatorRing(R) sage: f = 5*x^3 + 1/x + 1/(x-1) + 1/(3*x^2 + 1) sage: f - (15*x^7 - 15*x^6 + 5*x^5 - 5*x^4 + 6*x^3 - 2*x^2 + x - 1)/(3*x^4 - - 3*x^3 + x^2 - x) + (5*x^7 - 5*x^6 + 5/3*x^5 - 5/3*x^4 + 2*x^3 - 2/3*x^2 + 1/3*x - 1/3)/(x^4 - x^3 + 1/3*x^2 - 1/3*x) sage: decomp = FFPD(f).univariate_decomposition() sage: decomp (5*x^3, []) + diff --git a/src/sage/rings/cfinite_sequence.py b/src/sage/rings/cfinite_sequence.py index f2eb4611e30..f123c1e65c4 100644 --- a/src/sage/rings/cfinite_sequence.py +++ b/src/sage/rings/cfinite_sequence.py @@ -16,7 +16,7 @@ sage: fibo = CFiniteSequence(x/(1-x-x^2)) # the Fibonacci sequence sage: fibo - C-finite sequence, generated by x/(-x^2 - x + 1) + C-finite sequence, generated by -x/(x^2 + x - 1) sage: fibo.parent() The ring of C-Finite sequences in x over Rational Field sage: fibo.parent().category() @@ -27,13 +27,13 @@ sage: C The ring of C-Finite sequences in x over Rational Field sage: C(x/(1-x-x^2)) - C-finite sequence, generated by x/(-x^2 - x + 1) + C-finite sequence, generated by -x/(x^2 + x - 1) sage: C(x/(1-x-x^2)) == fibo True sage: var('y') y sage: CFiniteSequence(y/(1-y-y^2)) - C-finite sequence, generated by y/(-y^2 - y + 1) + C-finite sequence, generated by -y/(y^2 + y - 1) sage: CFiniteSequence(y/(1-y-y^2)) == fibo False @@ -135,7 +135,7 @@ def CFiniteSequences(base_ring, names = None, category = None): sage: C The ring of C-Finite sequences in x over Rational Field sage: C.an_element() - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: C.category() Category of commutative rings sage: C.one() @@ -147,7 +147,7 @@ def CFiniteSequences(base_ring, names = None, category = None): sage: C(1/x) Finite sequence [1], offset = -1 sage: C((-x + 2)/(-x^2 - x + 1)) - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) TESTS:: @@ -186,9 +186,9 @@ class CFiniteSequence(FieldElement): EXAMPLES:: sage: CFiniteSequence((2-x)/(1-x-x^2)) # the Lucas sequence - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: CFiniteSequence(x/(1-x)^3) # triangular numbers - C-finite sequence, generated by x/(-x^3 + 3*x^2 - 3*x + 1) + C-finite sequence, generated by -x/(x^3 - 3*x^2 + 3*x - 1) Polynomials are interpreted as finite sequences, or recurrences of degree 0:: @@ -208,12 +208,12 @@ class CFiniteSequence(FieldElement): sage: P = LaurentPolynomialRing(QQ.fraction_field(), 'X') sage: X=P.gen() sage: CFiniteSequence(1/(1-X)) - C-finite sequence, generated by 1/(-X + 1) + C-finite sequence, generated by -1/(X - 1) The o.g.f. is always normalized to get a denominator constant coefficient of `+1`:: sage: CFiniteSequence(1/(x-2)) - C-finite sequence, generated by -1/2/(-1/2*x + 1) + C-finite sequence, generated by 1/(x - 2) The given ``ogf`` is used to create an appropriate parent: it can be a symbolic expression, a polynomial , or a fraction field element @@ -240,7 +240,7 @@ class CFiniteSequence(FieldElement): sage: P. = QQ[] sage: CFiniteSequence(0.1/(1-x)) - C-finite sequence, generated by 1/10/(-x + 1) + C-finite sequence, generated by -1/10/(x - 1) sage: CFiniteSequence(pi/(1-x)) Traceback (most recent call last): ... @@ -270,14 +270,14 @@ def __classcall_private__(cls, ogf): sage: f1 = CFiniteSequence((2-x)/(1-x-x^2)) sage: f1 - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: C. = CFiniteSequences(QQ); sage: f2 = CFiniteSequence((2-x)/(1-x-x^2)) sage: f2 - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: f3 = C((2-x)/(1-x-x^2)) sage: f3 - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: f1 == f2 and f2 == f3 True sage: f1.parent() == f2.parent() and f2.parent() == f3.parent() @@ -298,7 +298,7 @@ def __classcall_private__(cls, ogf): y sage: f4 = CFiniteSequence((2-y)/(1-y-y^2)) sage: f4 - C-finite sequence, generated by (-y + 2)/(-y^2 - y + 1) + C-finite sequence, generated by (y - 2)/(y^2 + y - 1) sage: f4 == f1 False sage: f4.parent() == f1.parent() @@ -348,7 +348,7 @@ def __init__(self, parent, ogf): sage: C. = CFiniteSequences(QQ); sage: C((2-x)/(1-x-x^2)) # indirect doctest - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) """ br = parent.base_ring() @@ -517,7 +517,7 @@ def _div_(self, other): [1/2, 1, 3/2, 2, 5/2, 3] sage: s = C(x) sage: s/(s*-1 + 1) - C-finite sequence, generated by x/(-x + 1) + C-finite sequence, generated by -x/(x - 1) """ return CFiniteSequence(self.ogf() / (other.numerator() / other.denominator())) @@ -684,7 +684,7 @@ def ogf(self): sage: C. = CFiniteSequences(QQ) sage: r = C.from_recurrence([2],[1]) sage: r.ogf() - 1/(-2*x + 1) + -1/2/(x - 1/2) sage: C(0).ogf() 0 """ @@ -697,9 +697,9 @@ def numerator(self): EXAMPLES:: sage: f = CFiniteSequence((2-x)/(1-x-x^2)); f - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: f.numerator() - -x + 2 + x - 2 """ return self.ogf().numerator() @@ -710,9 +710,9 @@ def denominator(self): EXAMPLES:: sage: f = CFiniteSequence((2-x)/(1-x-x^2)); f - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: f.denominator() - -x^2 - x + 1 + x^2 + x - 1 """ return self.ogf().denominator() @@ -954,9 +954,9 @@ def _element_constructor_(self, ogf): sage: C. = CFiniteSequences(QQ) sage: C((2-x)/(1-x-x^2)) - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) sage: C(x/(1-x)^3) - C-finite sequence, generated by x/(-x^3 + 3*x^2 - 3*x + 1) + C-finite sequence, generated by -x/(x^3 - 3*x^2 + 3*x - 1) sage: C(x^2-4*x^5) Finite sequence [1, 0, 0, -4], offset = 2 sage: C(x^2+3/x) @@ -966,7 +966,7 @@ def _element_constructor_(self, ogf): sage: P = LaurentPolynomialRing(QQ.fraction_field(), 'X') sage: X = P.gen() sage: C(1/(1-X)) - C-finite sequence, generated by 1/(-x + 1) + C-finite sequence, generated by -1/(x - 1) sage: C = CFiniteSequences(QQ) sage: C(x) Finite sequence [1], offset = 1 @@ -1026,7 +1026,7 @@ def an_element(self): sage: C. = CFiniteSequences(QQ); sage: C.an_element() - C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1) + C-finite sequence, generated by (x - 2)/(x^2 + x - 1) """ x = self.gen() return self((2-x)/(1-x-x**2)) @@ -1121,7 +1121,7 @@ def from_recurrence(self, coefficients, values): sage: C. = CFiniteSequences(QQ) sage: C.from_recurrence([1,1],[0,1]) # Fibonacci numbers - C-finite sequence, generated by x/(-x^2 - x + 1) + C-finite sequence, generated by -x/(x^2 + x - 1) sage: C.from_recurrence([-1,2],[0,1]) # natural numbers C-finite sequence, generated by x/(x^2 - 2*x + 1) sage: r = C.from_recurrence([-1],[1]) @@ -1180,7 +1180,7 @@ def guess(self, sequence, algorithm='sage'): sage: C. = CFiniteSequences(QQ) sage: C.guess([1,2,4,8,16,32]) - C-finite sequence, generated by 1/(-2*x + 1) + C-finite sequence, generated by -1/2/(x - 1/2) sage: r = C.guess([1,2,3,4,5]) Traceback (most recent call last): ... @@ -1190,7 +1190,7 @@ def guess(self, sequence, algorithm='sage'): So with an odd number of values the result may not generate the last value:: sage: r = C.guess([1,2,4,8,9], algorithm='bm'); r - C-finite sequence, generated by 1/(-2*x + 1) + C-finite sequence, generated by -1/2/(x - 1/2) sage: r[0:5] [1, 2, 4, 8, 16] """ diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 4d6c2d6c4af..833d6738e12 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -289,7 +289,7 @@ cdef class FractionFieldElement(FieldElement): sage: R. = QQ[] sage: a = 2*(x+1)^2 / (2*(x-1)^2); a - (2*x^2 + 4*x + 2)/(2*x^2 - 4*x + 2) + (x^2 + 2*x + 1)/(x^2 - 2*x + 1) sage: a.numerator().is_square() False sage: a.is_square() @@ -888,7 +888,7 @@ cdef class FractionFieldElement(FieldElement): sage: x = PolynomialRing(RationalField(),'x').gen() sage: f = (x^3 + x)/(x^2 - 2*x^3) sage: f - (x^2 + 1)/(-2*x^2 + x) + (-1/2*x^2 - 1/2)/(x^2 - 1/2*x) sage: f.valuation() -1 sage: f.valuation(x^2+1) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index f616ca104db..65333d3a84e 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1010,7 +1010,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: f / x 1 + x + 3*x^3 sage: f / g - (3*x^11 + x^9 + x^8)/(-x^11 + x^9 - x^8 + 1) + (-3*x^11 - x^9 - x^8)/(x^11 - x^9 + x^8 - 1) sage: (x^-2 + x)*(x^-2 + 1) / ((x^5 + x^8)*(x + 2)) (x^2 + 1)/(x^10 + 2*x^9) sage: (x^-2 + x)*(x^-2 + 1) / ((x^-5 + x^-8)*(x + 2)) diff --git a/src/sage/rings/polynomial/polynomial_rational_flint.pyx b/src/sage/rings/polynomial/polynomial_rational_flint.pyx index 7255a54bc1f..1ec33804aa6 100644 --- a/src/sage/rings/polynomial/polynomial_rational_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_rational_flint.pyx @@ -1143,7 +1143,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: f^3 -1/27*t^6 + 2/3*t^5 - 23/6*t^4 + 6*t^3 + 23/4*t^2 + 3/2*t + 1/8 sage: f^(-3) - 1/(-1/27*t^6 + 2/3*t^5 - 23/6*t^4 + 6*t^3 + 23/4*t^2 + 3/2*t + 1/8) + -27/(t^6 - 18*t^5 + 207/2*t^4 - 162*t^3 - 621/4*t^2 - 81/2*t - 27/8) TESTS:: diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index dbfbb58a1cb..39770c36046 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -632,7 +632,7 @@ def completion(self, p, prec=20, extras=None): sage: PP(f) 1 - x sage: 1/f - 1/(-x + 1) + -1/(x - 1) sage: 1/PP(f) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) """ diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index 8a20cde0656..2aa3b20b3fb 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -1026,7 +1026,7 @@ def EllipticCurve_from_cubic(F, P=None, morphism=True): sage: R. = K[] sage: cubic = x^3+t*y^3+(1+t)*z^3 sage: EllipticCurve_from_cubic(cubic,[1,1,-1], morphism=False) - Elliptic Curve defined by y^2 + ((-236196*t^6-708588*t^5-1180980*t^4-1180980*t^3-708588*t^2-236196*t)/(-1458*t^6-17496*t^5+4374*t^4+29160*t^3+4374*t^2-17496*t-1458))*x*y + ((-459165024*t^14-5969145312*t^13-34207794288*t^12-113872925952*t^11-244304490582*t^10-354331909458*t^9-354331909458*t^8-244304490582*t^7-113872925952*t^6-34207794288*t^5-5969145312*t^4-459165024*t^3)/(-1458*t^14-58320*t^13-841266*t^12-5137992*t^11-11773350*t^10-7709904*t^9+12627738*t^8+25789104*t^7+12627738*t^6-7709904*t^5-11773350*t^4-5137992*t^3-841266*t^2-58320*t-1458))*y = x^3 + ((-118098*t^12-708588*t^11+944784*t^10+11219310*t^9+27871128*t^8+36374184*t^7+27871128*t^6+11219310*t^5+944784*t^4-708588*t^3-118098*t^2)/(-54*t^12-1296*t^11-7452*t^10+6048*t^9+25758*t^8-3888*t^7-38232*t^6-3888*t^5+25758*t^4+6048*t^3-7452*t^2-1296*t-54))*x^2 over Rational function field in t over Rational Field + Elliptic Curve defined by y^2 + ((162*t^6+486*t^5+810*t^4+810*t^3+486*t^2+162*t)/(t^6+12*t^5-3*t^4-20*t^3-3*t^2+12*t+1))*x*y + ((314928*t^14+4094064*t^13+23462136*t^12+78102144*t^11+167561379*t^10+243026001*t^9+243026001*t^8+167561379*t^7+78102144*t^6+23462136*t^5+4094064*t^4+314928*t^3)/(t^14+40*t^13+577*t^12+3524*t^11+8075*t^10+5288*t^9-8661*t^8-17688*t^7-8661*t^6+5288*t^5+8075*t^4+3524*t^3+577*t^2+40*t+1))*y = x^3 + ((2187*t^12+13122*t^11-17496*t^10-207765*t^9-516132*t^8-673596*t^7-516132*t^6-207765*t^5-17496*t^4+13122*t^3+2187*t^2)/(t^12+24*t^11+138*t^10-112*t^9-477*t^8+72*t^7+708*t^6+72*t^5-477*t^4-112*t^3+138*t^2+24*t+1))*x^2 over Rational function field in t over Rational Field TESTS: diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 6a260fea19e..0cf3be5c2f8 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -2072,7 +2072,7 @@ def multiplication_by_m(self, m, x_only=False): Grab only the x-coordinate (less work):: sage: mx = E.multiplication_by_m(2, x_only=True); mx - (x^4 + 2*x^2 - 24*x + 1)/(4*x^3 - 4*x + 12) + (1/4*x^4 + 1/2*x^2 - 6*x + 1/4)/(x^3 - x + 3) sage: mx.parent() Fraction Field of Univariate Polynomial Ring in x over Rational Field diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index 7f888c945fc..4c7a9ca4ae8 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -1042,7 +1042,7 @@ def Lattes_map(self, E, m): sage: P.Lattes_map(E, 2) Dynamical System of Projective Space of dimension 1 over Rational Field Defn: Defined on coordinates by sending (x : y) to - (x^4 + 2*x^2*y^2 + y^4 : 4*x^3*y - 4*x*y^3) + (1/4*x^4 + 1/2*x^2*y^2 + 1/4*y^4 : x^3*y - x*y^3) """ if self.dimension_relative() != 1: raise TypeError("must be dimension 1") diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 88509b7b6f9..a8ef51026d7 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -3091,7 +3091,7 @@ cdef class CommutativeRingElement(RingElement): sage: R. = QQ[] sage: a = 2*(x+1)^2 / (2*(x-1)^2); a.sqrt() - (2*x + 2)/(2*x - 2) + (x + 1)/(x - 1) sage: sqrtx=(1/x).sqrt(name="y"); sqrtx y sage: sqrtx^2 diff --git a/src/sage/tests/french_book/polynomes.py b/src/sage/tests/french_book/polynomes.py index 4f5af0dde7c..9173d8bcb02 100644 --- a/src/sage/tests/french_book/polynomes.py +++ b/src/sage/tests/french_book/polynomes.py @@ -224,7 +224,7 @@ Sage example in ./polynomes.tex, line 864:: sage: r.reduce(); r - 1.00000000000000/(-x + 1.00000000000000) + -1.00000000000000/(x - 1.00000000000000) Sage example in ./polynomes.tex, line 907:: From b71ab2d566bef202899147a8368aecf663043150 Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Mon, 23 Apr 2018 13:56:33 +0200 Subject: [PATCH 09/11] #16268 other doctest updates --- .../endPN_automorphism_group.py | 10 +++--- .../arithmetic_dynamics/projective_ds.py | 31 +++++++++++++++---- src/sage/rings/fraction_field_element.pyx | 2 -- .../function_field/function_field_element.pyx | 4 +-- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py b/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py index 4872b5ea66a..f44c5e3ee6a 100644 --- a/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py +++ b/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py @@ -64,7 +64,7 @@ def automorphism_group_QQ_fixedpoints(rational_function, return_functions=False, sage: rational_function = (z^2 - 2*z - 2)/(-2*z^2 - 2*z + 1) sage: from sage.dynamics.arithmetic_dynamics.endPN_automorphism_group import automorphism_group_QQ_fixedpoints sage: automorphism_group_QQ_fixedpoints(rational_function, True) - [z, 2/(2*z), -z - 1, -2*z/(2*z + 2), (-z - 1)/z, -1/(z + 1)] + [z, 1/z, -z - 1, -z/(z + 1), (-z - 1)/z, -1/(z + 1)] :: @@ -342,8 +342,8 @@ def PGL_repn(rational_function): sage: f = ((2*z-1)/(3-z)) sage: from sage.dynamics.arithmetic_dynamics.endPN_automorphism_group import PGL_repn sage: PGL_repn(f) - [ 2 -1] - [-1 3] + [-2 1] + [ 1 -3] """ if is_Matrix(rational_function): return rational_function @@ -1452,7 +1452,7 @@ def automorphisms_fixing_pair(rational_function, pair, quad): sage: L = [[4, 1], [2, 1]] sage: from sage.dynamics.arithmetic_dynamics.endPN_automorphism_group import automorphisms_fixing_pair sage: automorphisms_fixing_pair(f, L, False) - [(6*z + 6)/z, 4/(3*z + 3)] + [(6*z + 6)/z, 6/(z + 1)] """ # define ground field and ambient function field if rational_function.parent().is_field(): @@ -1526,7 +1526,7 @@ def automorphism_group_FF_alg3(rational_function): sage: f = (3456*z^4) sage: from sage.dynamics.arithmetic_dynamics.endPN_automorphism_group import automorphism_group_FF_alg3 sage: automorphism_group_FF_alg3(f) - [z, 3/(3*z)] + [z, 1/z] """ # define ground field and ambient function field if rational_function.parent().is_field(): diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index a05a211a6a0..dadbaa893f8 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -5520,12 +5520,31 @@ def automorphism_group(self, absolute=False, iso_type=False, return_functions=Fa sage: R. = ProjectiveSpace(GF(3^2,'t'),1) sage: f = DynamicalSystem_projective([x^3,y^3]) sage: f.automorphism_group(return_functions=True, iso_type=True) # long time - ([x, x/(x + 1), x/(2*x + 1), 2/(x + 2), (2*x + 1)/(2*x), (2*x + 2)/x, - 1/(2*x + 2), x + 1, x + 2, x/(x + 2), 2*x/(x + 1), 2*x, 1/x, 2*x + 1, - 2*x + 2, ((t + 2)*x + t + 2)/((2*t + 1)*x + t + 2), (t*x + 2*t)/(t*x + - t), 2/x, (x + 1)/(x + 2), (2*t*x + t)/(t*x), (2*t + 1)/((2*t + 1)*x + - 2*t + 1), ((2*t + 1)*x + 2*t + 1)/((2*t + 1)*x), t/(t*x + 2*t), (2*x + - 1)/(x + 1)], 'PGL(2,3)') + ([x, + x/(x + 1), + x/(2*x + 1), + 2/(x + 2), + (2*x + 1)/(2*x), + (2*x + 2)/x, + 1/(2*x + 2), + x + 1, + x + 2, + x/(x + 2), + 2*x/(x + 1), + 2*x, + 1/x, + 2*x + 1, + 2*x + 2, + (x + 2)/(x + 1), + 2/x, + (2*x + 2)/(x + 2), + (x + 1)/(x + 2), + (2*x + 1)/x, + 1/(x + 1), + 1/(x + 2), + (2*x + 1)/(x + 1), + (x + 1)/x], + 'PGL(2,3)') :: diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 833d6738e12..a736315f093 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -290,8 +290,6 @@ cdef class FractionFieldElement(FieldElement): sage: R. = QQ[] sage: a = 2*(x+1)^2 / (2*(x-1)^2); a (x^2 + 2*x + 1)/(x^2 - 2*x + 1) - sage: a.numerator().is_square() - False sage: a.is_square() True sage: (0/x).is_square() diff --git a/src/sage/rings/function_field/function_field_element.pyx b/src/sage/rings/function_field/function_field_element.pyx index 18c74ce02a0..df7111ed412 100644 --- a/src/sage/rings/function_field/function_field_element.pyx +++ b/src/sage/rings/function_field/function_field_element.pyx @@ -591,13 +591,13 @@ cdef class FunctionFieldElement_rational(FunctionFieldElement): sage: t.element() t sage: type(t.element()) - + <... 'sage.rings.fraction_field_FpT.FpTElement'> sage: K. = FunctionField(GF(131101)) sage: t.element() t sage: type(t.element()) - + <... 'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'> """ return self._x From e663dbe550077471e93046163f63f6706a8a4fb7 Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Sat, 12 May 2018 08:23:43 +0200 Subject: [PATCH 10/11] fix normalization of leading coefficients --- .../quatalg/quaternion_algebra_element.pyx | 2 +- src/sage/combinat/sf/hall_littlewood.py | 10 +++--- src/sage/combinat/sf/macdonald.py | 4 +-- .../dynamics/arithmetic_dynamics/affine_ds.py | 7 ++-- .../endPN_automorphism_group.py | 16 +++++---- .../arithmetic_dynamics/projective_ds.py | 6 ++-- src/sage/matrix/matrix2.pyx | 2 +- ...otics_multivariate_generating_functions.py | 9 ++--- src/sage/rings/fraction_field_element.pyx | 34 ++++++++++++++++--- .../rings/function_field/function_field.py | 19 +++++------ .../function_field/function_field_element.pyx | 6 ++-- src/sage/rings/function_field/maps.py | 8 ++--- .../rings/polynomial/polynomial_element.pyx | 2 +- .../schemes/elliptic_curves/ell_generic.py | 2 +- 14 files changed, 75 insertions(+), 52 deletions(-) diff --git a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx index 4b3bcba4881..fbfa2bf171c 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx @@ -843,7 +843,7 @@ cdef class QuaternionAlgebraElement_generic(QuaternionAlgebraElement_abstract): sage: type(theta) <... 'sage.algebras.quatalg.quaternion_algebra_element.QuaternionAlgebraElement_generic'> sage: theta._repr_() - '1/x + x*i + (-x - 1)*j + (2/(3*x^3 + 5))*k' + '1/x + x*i + (-x - 1)*j + (2/3/(x^3 + 5/3))*k' """ return self._do_print(self.x, self.y, self.z, self.w) diff --git a/src/sage/combinat/sf/hall_littlewood.py b/src/sage/combinat/sf/hall_littlewood.py index a096f7a9355..a46da3face0 100644 --- a/src/sage/combinat/sf/hall_littlewood.py +++ b/src/sage/combinat/sf/hall_littlewood.py @@ -662,7 +662,7 @@ def scalar_hl(self, x, t = None): sage: HLQ([2]).scalar_hl(HLQ([1,1])) 0 sage: HLP([2]).scalar_hl(HLP([2])) - 1/(-t + 1) + -1/(t - 1) """ parent = self.parent() if t is None: @@ -837,13 +837,13 @@ def __init__(self, hall_littlewood): sage: HLQp = Sym.hall_littlewood().Qp() sage: s = Sym.schur(); p = Sym.power() sage: HLQ( HLP([2,1]) + HLP([3]) ) - (1/(t^2-2*t+1))*HLQ[2, 1] + (1/(-t+1))*HLQ[3] + (1/(t^2-2*t+1))*HLQ[2, 1] - (1/(t-1))*HLQ[3] sage: HLQ(HLQp([2])) # indirect doctest - (t/(t^3-t^2-t+1))*HLQ[1, 1] + (1/(-t+1))*HLQ[2] + (t/(t^3-t^2-t+1))*HLQ[1, 1] - (1/(t-1))*HLQ[2] sage: HLQ(s([2])) - (t/(t^3-t^2-t+1))*HLQ[1, 1] + (1/(-t+1))*HLQ[2] + (t/(t^3-t^2-t+1))*HLQ[1, 1] - (1/(t-1))*HLQ[2] sage: HLQ(p([2])) - (1/(t^2-1))*HLQ[1, 1] + (1/(-t+1))*HLQ[2] + (1/(t^2-1))*HLQ[1, 1] - (1/(t-1))*HLQ[2] """ HallLittlewood_generic.__init__(self, hall_littlewood) diff --git a/src/sage/combinat/sf/macdonald.py b/src/sage/combinat/sf/macdonald.py index 254600dc88b..0d6ce7cd9e7 100644 --- a/src/sage/combinat/sf/macdonald.py +++ b/src/sage/combinat/sf/macdonald.py @@ -782,12 +782,12 @@ def _s_to_self(self, x): sage: J = Sym.macdonald(t=2).J() sage: s = Sym.schur() sage: J._s_to_self(s[2,1]) - ((-q+2)/(28*q-7))*McdJ[1, 1, 1] + (1/(-4*q+1))*McdJ[2, 1] + ((-1/28*q+1/14)/(q-1/4))*McdJ[1, 1, 1] - (1/4/(q-1/4))*McdJ[2, 1] This is for internal use only. Please use instead:: sage: J(s[2,1]) - ((-q+2)/(28*q-7))*McdJ[1, 1, 1] + (1/(-4*q+1))*McdJ[2, 1] + ((-1/28*q+1/14)/(q-1/4))*McdJ[1, 1, 1] - (1/4/(q-1/4))*McdJ[2, 1] """ return self._from_cache(x, self._s_cache, self._s_to_self_cache, q = self.q, t = self.t) diff --git a/src/sage/dynamics/arithmetic_dynamics/affine_ds.py b/src/sage/dynamics/arithmetic_dynamics/affine_ds.py index 43261e8afd6..ebc01fe702f 100644 --- a/src/sage/dynamics/arithmetic_dynamics/affine_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/affine_ds.py @@ -699,9 +699,10 @@ def orbit(self, P, n): sage: A. = AffineSpace(FractionField(R), 2) sage: f = DynamicalSystem_affine([(x-t*y^2)/x, t*x*y]) sage: f.orbit(A(1, t), 3) - [(1, t), (-t^3 + 1, t^2), ((-t^5 - t^3 + 1)/(-t^3 + 1), -t^6 + t^3), - ((-t^16 + 3*t^13 - 3*t^10 + t^7 + t^5 + t^3 - 1)/(t^5 + t^3 - 1), -t^9 - - t^7 + t^4)] + [(1, t), + (-t^3 + 1, t^2), + ((t^5 + t^3 - 1)/(t^3 - 1), -t^6 + t^3), + ((-t^16 + 3*t^13 - 3*t^10 + t^7 + t^5 + t^3 - 1)/(t^5 + t^3 - 1), -t^9 - t^7 + t^4)] """ Q = P if isinstance(n, list) or isinstance(n, tuple): diff --git a/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py b/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py index f44c5e3ee6a..7ee79dd4b48 100644 --- a/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py +++ b/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py @@ -1083,7 +1083,7 @@ def three_stable_points(rational_function, invariant_list): sage: L = [[0,1],[4,1],[1,1],[1,0]] sage: from sage.dynamics.arithmetic_dynamics.endPN_automorphism_group import three_stable_points sage: three_stable_points(f,L) - [z, 4*z, 2/(2*z), 3/(2*z)] + [z, 4*z, 1/z, 4/z] """ # define ground field and ambient function field if rational_function.parent().is_field(): @@ -1151,7 +1151,7 @@ def automorphism_group_FF_alg2(rational_function): sage: f = (3*z^3 - z^2)/(z-1) sage: from sage.dynamics.arithmetic_dynamics.endPN_automorphism_group import automorphism_group_FF_alg2 sage: automorphism_group_FF_alg2(f) - [Univariate Polynomial Ring in w over Finite Field in b of size 7^2, [w, (3*b + 2)/((2*b + 6)*w)]] + [Univariate Polynomial Ring in w over Finite Field in b of size 7^2, [w, 5/w]] :: @@ -1159,11 +1159,13 @@ def automorphism_group_FF_alg2(rational_function): sage: f = (3456*z^(4)) sage: from sage.dynamics.arithmetic_dynamics.endPN_automorphism_group import automorphism_group_FF_alg2 sage: automorphism_group_FF_alg2(f) - [Univariate Polynomial Ring in w over Finite Field in b of size 5^6, [w, - (3*b^5 + 4*b^4 + 3*b^2 + 2*b + 1)*w, (2*b^5 + b^4 + 2*b^2 + 3*b + 3)*w, - (3*b^5 + 4*b^4 + 3*b^2 + 2*b)/((3*b^5 + 4*b^4 + 3*b^2 + 2*b)*w), (4*b^5 - + 2*b^4 + 4*b^2 + b + 2)/((3*b^5 + 4*b^4 + 3*b^2 + 2*b)*w), (3*b^5 + - 4*b^4 + 3*b^2 + 2*b + 3)/((3*b^5 + 4*b^4 + 3*b^2 + 2*b)*w)]] + [Univariate Polynomial Ring in w over Finite Field in b of size 5^6, + [w, + (3*b^5 + 4*b^4 + 3*b^2 + 2*b + 1)*w, + (2*b^5 + b^4 + 2*b^2 + 3*b + 3)*w, + 1/w, + (3*b^5 + 4*b^4 + 3*b^2 + 2*b + 1)/w, + (2*b^5 + b^4 + 2*b^2 + 3*b + 3)/w]] """ # define ground field and ambient function field if rational_function.parent().is_field(): diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index dadbaa893f8..3db56326e52 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -5522,11 +5522,11 @@ def automorphism_group(self, absolute=False, iso_type=False, return_functions=Fa sage: f.automorphism_group(return_functions=True, iso_type=True) # long time ([x, x/(x + 1), - x/(2*x + 1), + 2*x/(x + 2), 2/(x + 2), - (2*x + 1)/(2*x), + (x + 2)/x, (2*x + 2)/x, - 1/(2*x + 2), + 2/(x + 1), x + 1, x + 2, x/(x + 2), diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index e21d1d9185b..8509d63bbe0 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -331,7 +331,7 @@ cdef class Matrix(Matrix1): sage: v = vector([3,4*x - 2]) sage: X = A \ v sage: X - ((-8*x^2 + 4*x + 9)/(10*x^3 + x), (19*x^2 - 2*x - 3)/(10*x^3 + x)) + ((-4/5*x^2 + 2/5*x + 9/10)/(x^3 + 1/10*x), (19/10*x^2 - 1/5*x - 3/10)/(x^3 + 1/10*x)) sage: A * X == v True diff --git a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py index 9629a44c58e..1f40e6edbd5 100644 --- a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +++ b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py @@ -802,10 +802,7 @@ def univariate_decomposition(self): sage: FFPD = FractionWithFactoredDenominatorRing(R) sage: f = 5*x^3 + 1/x + 1/(x-1) + 1/(3*x^2 + 1) sage: f - (15.0000000000000*x^7 - 15.0000000000000*x^6 + 5.00000000000000*x^5 - - 5.00000000000000*x^4 + 6.00000000000000*x^3 - - 2.00000000000000*x^2 + x - 1.00000000000000)/(3.00000000000000*x^4 - - 3.00000000000000*x^3 + x^2 - x) + (5.00000000000000*x^7 - 5.00000000000000*x^6 + 1.66666666666667*x^5 - 1.66666666666667*x^4 + 2.00000000000000*x^3 - 0.666666666666667*x^2 + 0.333333333333333*x - 0.333333333333333)/(x^4 - x^3 + 0.333333333333333*x^2 - 0.333333333333333*x) sage: decomp = FFPD(f).univariate_decomposition() sage: decomp (5.00000000000000*x^3, []) + @@ -2762,9 +2759,7 @@ def smooth_critical_ideal(self, alpha): sage: F = FFPD(G, Hfac) sage: alpha = [7/3, var('a')] sage: F.smooth_critical_ideal(alpha) - Ideal (y^2 + 14/(3*a)*y - 1, x + (-3/7*a)*y + 3/7*a - 1) of - Multivariate Polynomial Ring in x, y over Fraction Field of - Univariate Polynomial Ring in a over Rational Field + Ideal (y^2 + 14/3/a*y - 1, x + (-3/7*a)*y + 3/7*a - 1) of Multivariate Polynomial Ring in x, y over Fraction Field of Univariate Polynomial Ring in a over Rational Field """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index a736315f093..c00751bbbdc 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -67,7 +67,7 @@ cdef class FractionFieldElement(FieldElement): True sage: x = K.gen() sage: f = (x^3 + x)/(17 - x^19); f - (x^3 + x)/(-x^19 + 17) + (-x^3 - x)/(x^19 - 17) sage: loads(f.dumps()) == f True @@ -1062,6 +1062,32 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): Many of the functions here are included for coherence with number fields. """ + + def __init__(self, parent, numerator, denominator=1, + coerce=True, reduce=True): + """ + TESTS: + + sage: P. = QQ[] + sage: a = (2*x^2)/x + sage: ~a + 1/2/x + sage: 1/a + 1/2/x + """ + FractionFieldElement.__init__(self, parent, numerator, denominator, + coerce, reduce) + if not reduce: + self.normalize_leading_coefficients() + + cdef normalize_leading_coefficients(self): + """ + See :meth:`reduce`. + """ + invlc = ~self.__denominator.leading_coefficient() + self.__denominator = self.__denominator.monic() + self.__numerator *= invlc + def is_integral(self): """ Returns whether this element is actually a polynomial. @@ -1119,10 +1145,10 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): sage: (2 + 2*x) / (4*x) (x + 1)/(2*x) """ + if self._is_reduced: + return super(self.__class__, self).reduce() - invlc = ~self.__denominator.leading_coefficient() - self.__denominator = self.__denominator.monic() - self.__numerator *= invlc + self.normalize_leading_coefficients() def make_element(parent, numerator, denominator): """ diff --git a/src/sage/rings/function_field/function_field.py b/src/sage/rings/function_field/function_field.py index 97eabec4a11..717b292769d 100644 --- a/src/sage/rings/function_field/function_field.py +++ b/src/sage/rings/function_field/function_field.py @@ -32,7 +32,7 @@ sage: y^3 2*x*y + (x^4 + 1)/x sage: a = 1/y; a - (4*x/(4*x^4 + 4))*y^2 + 2*x^2/(4*x^4 + 4) + (x/(x^4 + 1))*y^2 + 3*x^2/(x^4 + 1) sage: a * y 1 @@ -46,7 +46,7 @@ sage: t^2 x*y sage: 1/t - ((1/(x^4 + 1))*y^2 + 2*x/(4*x^4 + 4))*t + ((1/(x^4 + 1))*y^2 + 3*x/(x^4 + 1))*t sage: M.base_field() Function field in y defined by y^3 + 3*x*y + (4*x^4 + 4)/x sage: M.base_field().base_field() @@ -221,7 +221,7 @@ def some_elements(self): 1/x^2, x/(x^2 - 1), x/(x^2 + 1), - x/(2*x^2 + 2), + 1/2*x/(x^2 + 1), 0, 1/x, ...] @@ -234,14 +234,13 @@ def some_elements(self): [1, y, 1/x*y, - ((1/4*x + 1/4)/(1/4*x^2 - 1/2*x + 1/4))*y - 1/2*x/(1/4*x^2 - 1/2*x + 1/4), - -1/-x, + ((x + 1)/(x^2 - 2*x + 1))*y - 2*x/(x^2 - 2*x + 1), + 1/x, (1/(x - 1))*y, (1/(x + 1))*y, - (1/(2*x + 2))*y, + (1/2/(x + 1))*y, 0, ...] - """ elements = [] @@ -778,7 +777,7 @@ class FunctionField_polymod(FunctionField): sage: M. = L.extension(z^2 + y*z + y); M Function field in z defined by z^2 + y*z + y sage: 1/z - ((x/(-x^4 - 1))*y^4 - 2*x^2/(-x^4 - 1))*z - 1 + ((-x/(x^4 + 1))*y^4 + 2*x^2/(x^4 + 1))*z - 1 sage: z * (1/z) 1 @@ -1438,12 +1437,12 @@ def vector_space(self, base=None): We define an interesting element of the function field:: sage: a = 1/L.0; a - (-x/(-x^4 - 1))*y^4 + 2*x^2/(-x^4 - 1) + (x/(x^4 + 1))*y^4 - 2*x^2/(x^4 + 1) We convert it to the vector space, and get a vector over the base field:: sage: to_V(a) - (2*x^2/(-x^4 - 1), 0, 0, 0, -x/(-x^4 - 1)) + (-2*x^2/(x^4 + 1), 0, 0, 0, x/(x^4 + 1)) We convert to and back, and get the same element:: diff --git a/src/sage/rings/function_field/function_field_element.pyx b/src/sage/rings/function_field/function_field_element.pyx index df7111ed412..6ef8d6e2e5a 100644 --- a/src/sage/rings/function_field/function_field_element.pyx +++ b/src/sage/rings/function_field/function_field_element.pyx @@ -513,7 +513,7 @@ cdef class FunctionFieldElement_polymod(FunctionFieldElement): sage: K. = FunctionField(QQ); R. = K[] sage: L. = K.extension(y^2 - x*y + 4*x^3) sage: a = ~(2*y + 1/x); a # indirect doctest - (-x^2/(8*x^5 + x^2 + 1/2))*y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) + (-1/8*x^2/(x^5 + 1/8*x^2 + 1/16))*y + (1/8*x^3 + 1/16*x)/(x^5 + 1/8*x^2 + 1/16) sage: a*(2*y + 1/x) 1 """ @@ -534,9 +534,9 @@ cdef class FunctionFieldElement_polymod(FunctionFieldElement): sage: K. = FunctionField(QQ); R. = K[] sage: L. = K.extension(y^2 - x*y + 4*x^3) sage: a = ~(2*y + 1/x); a - (-x^2/(8*x^5 + x^2 + 1/2))*y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) + (-1/8*x^2/(x^5 + 1/8*x^2 + 1/16))*y + (1/8*x^3 + 1/16*x)/(x^5 + 1/8*x^2 + 1/16) sage: a.list() - [(2*x^3 + x)/(16*x^5 + 2*x^2 + 1), -x^2/(8*x^5 + x^2 + 1/2)] + [(1/8*x^3 + 1/16*x)/(x^5 + 1/8*x^2 + 1/16), -1/8*x^2/(x^5 + 1/8*x^2 + 1/16)] sage: (x*y).list() [0, x] """ diff --git a/src/sage/rings/function_field/maps.py b/src/sage/rings/function_field/maps.py index c09fb6db963..7a69dbbfb17 100644 --- a/src/sage/rings/function_field/maps.py +++ b/src/sage/rings/function_field/maps.py @@ -197,7 +197,7 @@ class FunctionFieldDerivation_separable(FunctionFieldDerivation): Derivation map: From: Function field in y defined by y^2 - x To: Function field in y defined by y^2 - x - Defn: y |--> (-1/2/-x)*y + Defn: y |--> 1/2/x*y """ def __init__(self, L, d): """ @@ -248,7 +248,7 @@ def _call_(self, x): sage: d(x) # indirect doctest 1 sage: d(y) - (-1/2/-x)*y + 1/2/x*y sage: d(y^2) 1 """ @@ -273,7 +273,7 @@ def _repr_defn(self): Derivation map: From: Function field in y defined by y^2 - x To: Function field in y defined by y^2 - x - Defn: y |--> (-1/2/-x)*y + Defn: y |--> 1/2/x*y sage: R. = L[] sage: M. = L.extension(z^2 - y) @@ -281,7 +281,7 @@ def _repr_defn(self): Derivation map: From: Function field in z defined by z^2 - y To: Function field in z defined by z^2 - y - Defn: y |--> (-1/2/-x)*y + Defn: y |--> 1/2/x*y z |--> 1/4/x*z """ base = self._d._repr_defn() diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 21a91601485..a401dbfff63 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -8401,7 +8401,7 @@ cdef class Polynomial(CommutativeAlgebraElement): sage: m = z^9; sage: n, d = p.rational_reconstruct(m); sage: print((n ,d)) - ((1/-t)*z^4 - t*z + 1/-t, z + 1/-t) + (-1/t*z^4 - t*z - 1/t, z - 1/t) sage: print(((p*d - n) % m ).is_zero()) True sage: w = PowerSeriesRing(P.fraction_field(), 'w').gen() diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 0cf3be5c2f8..d4d9ebf09ea 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -813,7 +813,7 @@ def lift_x(self, x, all=False, extend=False): sage: -P (x : -y : 1) sage: 2*P - ((1/4*x^4 - 4*x)/(x^3 + 2) : ((-1/8*x^6 - 5*x^3 + 4)/(-x^6 - 4*x^3 - 4))*y : 1) + ((1/4*x^4 - 4*x)/(x^3 + 2) : ((1/8*x^6 + 5*x^3 - 4)/(x^6 + 4*x^3 + 4))*y : 1) AUTHOR: From db762fc4082cf6af913a7637b895f970a7492a74 Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Sun, 10 Jun 2018 14:44:31 +0200 Subject: [PATCH 11/11] additional doctest update after #25440 --- src/sage/rings/fraction_field_element.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index c00751bbbdc..d80263e1660 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -1030,7 +1030,7 @@ cdef class FractionFieldElement(FieldElement): sage: L = R.fraction_field() sage: S. = L[] sage: y(K(1,1)/x) - ((1 + O(2)))/((1 + O(2^5))*x) + ((1 + O(2)))/((1 + O(2))*x) """ if self.numerator().is_one():